我有散列如何散列的數組中的計數值
[ {:name => "bob", :type => "some", :product => "apples"},
{:name => "ted", :type => "other", :product => "apples"},....
{:name => "Will", :type => "none", :product => "oranges"} ]
的數組,並想知道如果有一個簡單的方法來計算產品的數量和將計以及在價值一個數組或散列。
我想要的結果是這樣的:
@products = [{"apples" => 2, "oranges => 1", ...}]
根據自己的需要,我沒有看到有任何理由將散列保留在Array中。有什麼理由,然後告訴我們。 –
您的預計結果無效。這是不可能的。 – sawa