tags:

views:

41

answers:

1

I would like to know ice cream preferences of all my cats in an array.

So the output would be just the :ice_cream out of all the cat's :

[ "vanilla", "chocolate", "mint chocolate", "mice" ]

While the cat objects are :

cat => {:ice_cream => "chocolate", :paws => "4", :wants_to_kill_humans => "yes" }

Yikes this is such an easy answer I bet, but I can't find it anywhere.

+3  A: 

You want something like:

@cats.collect {|cat| cat[:ice_cream] }
Ben
Yes! Thank you so much Ben! I can't believe i couldn't figure this out. Thanks so much.
Trip
yw. Feel free to accept the answer.
Ben
they make me wait.. thanks again
Trip
Ahhhhh. Gotcha.
Ben
strange.. that groups all the params together as one giant word. do you have to use gsub to seperate them into arrays?
Trip
If you call to_s on an array of strings, you would see exactly what you described. Try printing the strings returned from inspect. You should see an array:`puts @cats.collect { |c| c[:ice_cream] }.inspect``=> ["vanilla", "chocolate"]`
Todd Yandell