Ruby on Rails 3.2.2、Ruby 1.9.3
我有来自 Siz.requirements.all (model) 模型字段 (siz,heigth,wigth,kol) 的数组数据
[{:siz=>10, :heigth = 30, :wigth = 20, :kol = 24},
{:siz=>10, :heigth = 30, :wigth = 10, :kol = 24},
{:siz=>10, :heigth = 30, :wigth = 20, :kol = 33},
{:siz=>10, :heigth = 20, :wigth = 20, :kol = 3},
{:siz=>10, :heigth = 20, :wigth = 20, :kol = 5},...
如何使用 group by 字段创建数组或哈希,例如:
[{:siz=>10 => {:heigth=>"30" => {:wigth=>"20" => {:sum_kol => sum(kol)}}},
{:siz=>10 => {:heigth=>"30" => {:wigth=>"10" => {:sum_kol => sum(kol)}}},
{:siz=>10 => {:heigth=>"20" => {:wigth=>"20" => {:sum_kol => sum(kol)}}}]