From: Kenichi Kamiya Date: 2012-01-17T01:21:51+09:00 Subject: Re: uniq with count; better way? I like this a = [4,5,6,4,5,6,6,7] # 1 p Hash[a.group_by{|n|n}.map{|k, v|[k, v.size]}] # 2 p Hash.new(0).tap{|h|a.each{|n|h[n] += 1}} 2012/1/17 Ralph Shnelvar : > a = [4,5,6,4,5,6,6,7] > > result = Hash.new(0) > a.each { |x|  result[x] += 1 } > > p result > > > > The result I am getting >   {4=>2, 5=>2, 6=>3, 7=>1} > is what I want. > > Is there a better way; perhaps using uniq? > >