On Feb 24, 1:29 pm, Erwin <[email protected]> wrote:
> I have an array of hash :
> tags_on
>  => [{:point=>["a", "b", "c"]}, {:comma=>["d", "e"]}]
>
> and I would like to get the value ["d", "e"] for a specified
> key  :comma
> is there any DRY way to do it or should I loop into the array ?

For reference, this will do what you're looking for (array starts in
tags_on, key in desired_key):

hash = tags_on.detect { |h| h.has_key?(desired_key) }
result = hash[desired_key] if hash

I've had to build little arrays of single-key hashes like this to work
around 1.8.6 not having ordered hash semantics.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to