嘿,我有一个哈希值数组,如下所示。
[{"group" => "1", "message" => "hey", "weight" => 1}, {"group" => "1", "message"
=> "hey1", "weight" => 2}, {"group" => "2", "message" => "hey3", "weight" => 4}]
我想 group_by 组并对其进行格式化,以便获得以下信息:
[{"group" => 1, "messages" => {"hey","hey1"}, "weights" => {1,2}}, {"group" => 2,
"messages" => {"hey3"}, "weights" => {4}}]
有没有很好的红宝石方法来实现这一目标?
编辑:现在我有:
[
{"group" => "1", "message" => {"hey" => "1"}},
{"group" => "1", "message" => {"hey1" => "2"}}
]
我想拥有
{"group" => "1", "messages" => {"hey1" => "1", "hey2" => "2"} }