鑑於哈希基於一些關鍵
arr = [{'city' => 'Bangalore','device' => 'desktop','users' => '20'},
{'city' => 'Bangalore','device' => 'tablet','users' => '20'},
{'city' => 'Bangalore','device' => 'mobile','users' => '20'},
{'city' => 'Pune','device' => 'desktop','users' => '20'},
{'city' => 'Pune','device' => 'tablet','users' => '20'},
{'city' => 'Pune','device' => 'mobile','users' => '20'},
{'city' => 'Mumbai','device' => 'desktop','users' => '20'},
{'city' => 'Mumbai','device' => 'tablet','users' => '20'},
{'city' => 'Mumbai','device' => 'mobile','users' => '20'}]
我怎麼能生產出哈希以下數組的數組的值如何聚合紅寶石哈希?
[{'city' => 'Bangalore', 'users' => '60'},
{'city' => 'Pune', 'users' => '60'},
{'city' => 'Mumbai','users' => '60'}]
是此活動記錄的對象? – uzaif
你有試過什麼嗎? –
這不是主動記錄,我用過每個循環並建立了一個新對象,但我想知道更好的方法 – Neevany