On Tue, Sep 25, 2012 at 11:31 AM, Jan E. <lists / ruby-forum.com> wrote:
> Hi,
>
> Using "inject" really isn't a good choice here. If at all, I'd use
> "each_with_object" to build up the hash.

My preferred solution:

count = [1,2,1,1]
h = Hash.new(0)
count.each {|el| h[el] += 1}
p h #=> {1=>3, 2=>1}


Jesus.