我在 Ruby 中有一个哈希数组,如下所示:
domains = [
{ "country" => "Germany"},
{"country" => "United Kingdom"},
{"country" => "Hungary"},
{"country" => "United States"},
{"country" => "France"},
{"country" => "Germany"},
{"country" => "Slovakia"},
{"country" => "Hungary"},
{"country" => "United States"},
{"country" => "Norway"},
{"country" => "Germany"},
{"country" => "United Kingdom"},
{"country" => "Hungary"},
{"country" => "United States"},
{"country" => "Norway"}
]
从这个哈希数组中,我想创建一个看起来像这样的新哈希:
counted = {
"Germany" => "3",
"United Kingdom" => "United Kingdom",
"Hungary" => "3",
"United States" => "4",
"France" => "1"
}
有没有使用 Ruby 1.9 的简单方法来做到这一点?