I would like to know ice cream preferences of all my cats in an array.
So the output would开发者_如何学C 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.
You want something like:
@cats.collect {|cat| cat[:ice_cream] }
精彩评论