标签: ruby hash
我想将哈希的键/值对转换为值。例如,我的哈希是:
{"place"=>1, "gentleman"=>1}
我希望它必须是这样的:
[{'word'=>'place','count'=>1},{'word'=>'gentleman','count'=>1}]
答案 0 :(得分:0)
您可以尝试类似
my_hash.map { |word, count| {'word' => word, 'count'=> count} }