Re: associative array naming indirection

the array is in has a method that takes an array of string values.
end

foo(:a, :b, :c)

You can read about Array#zip and Array#flatten on the documentation
pages, or by using ri from the terminal, e.g.

$ ri Array#zip

Cheers,
Daniel

The above works great if you’re limited to the standard library.
However, if you’re allowed to use third party packages, I prefer hash
slices for this sort of thing:

require ‘hashslice’

def adddata(data)
@pageData[
@labels] = *data
end

IMHO this behavior should exist in the current Hash class. :slight_smile:

Regards,

Dan

This communication is the property of Qwest and may contain confidential
or
privileged information. Unauthorized use of this communication is
strictly
prohibited and may be unlawful. If you have received this communication
in error, please immediately notify the sender by reply e-mail and
destroy
all copies of the communication and any attachments.

Berger, Daniel wrote:

the array is in has a method that takes an array of string values.
end
Hash.[] takes an argument list with the even items being the keys and
foo(:a, :b, :c)
The above works great if you’re limited to the standard library.
However, if you’re allowed to use third party packages, I prefer hash
slices for this sort of thing:

require ‘hashslice’

def adddata(data)
@pageData[
@labels] = *data
end

IMHO this behavior should exist in the current Hash class. :slight_smile:

I agree, and I’m using it myself. I just usually try to limit myself to
the standard library when answering questions on this list, to minimize
the hazzle the user has to go through.

Cheers,
Daniel

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs