所以我使用:
hashA.keys.each do |i| puts hashA[i] end
输出示例:
0 1 1 2 0 1 1
我希望新的Hash如下:
{ 0 => 2,1 => 4,2 => 1 }
counts = hashA.values.inject(Hash.new(0)) do |collection,value| collection[value] +=1 collection end