开发者

How do you pull a single attribute out of an array of hashes?

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] }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜