假设我有一个数组:
array = [{"account_id"=>"01", "ad"=>"1"},
{"account_id"=>"05", "ad"=>"2"},
{"account_id"=>"05", "ad"=>"3"},
{"account_id"=>"01", "ad"=>"2"},
{"account_id"=>"10", "ad"=>"3"},
{"account_id"=>"04", "ad"=>"4"}]
我如何将它分成按 account_id 划分的组,例如
l1 = [{"account_id"=>"01", "ad"=>"1"},{"account_id"=>"01", "ad"=>"2"}]
l2 = [{"account_id"=>"05", "ad"=>"2"},{"account_id"=>"05", "ad"=>"3"}]
....
然后将列表一起返回。
我怎样才能做到这一点?是否有任何现有的 API?此外,我正在考虑使用列表列表之类的数据结构(就像List<List<Map<String, String>>>在 Java 中一样?对不起,我是 Ruby 新手),但如果有更好的呈现方式,请告诉我。谢谢