进行以下数据结构转换的“Rubyist”方式是什么:
我有
传入 = [ {:date => 20090501, :width => 2},
{:date => 20090501,:height => 7},
{:date => 20090501,:depth => 3},
{:date => 20090502,:width => 4},
{:date => 20090502,:height => 6},
{:date => 20090502,:depth => 2},
]
我想在 :date 之前折叠这些,最终得到
传出 = [ {:date => 20090501, :width => 2, :height => 7, :depth => 3},
{:date => 20090502,:width => 4,:height => 6,:depth => 2},
]
如果列在每行中的顺序相同,则数组数组在最后一步也可以。另外,重要的是,我事先并不知道所有的哈希键(也就是说,我不知道 :width、:height 或 :depth ——它们可能是 :cats、:dogs 和 :hamsters)。