I like this

a =3D [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] +=3D 1}}


2012/1/17 Ralph Shnelvar <ralphs / dos32.com>:
> a =3D [4,5,6,4,5,6,6,7]
>
> result =3D Hash.new(0)
> a.each { |x| =A0result[x] +=3D 1 }
>
> p result
>
>
>
> The result I am getting
> =A0 {4=3D>2, 5=3D>2, 6=3D>3, 7=3D>1}
> is what I want.
>
> Is there a better way; perhaps using uniq?
>
>