On Tuesday, July 20, 2010 10:05:27 am Rob Biedenharn wrote:
> On Jul 20, 2010, at 10:58 AM, Vitaliy Yanchuk wrote:
> > Jean-Julien Fleck wrote:
> >> 2010/7/20 Vitaliy Yanchuk <fuksito / gmail.com>:
> >>> Jean-Julien Fleck, thanks.
> >>> Maybe have an idea of a one-line version? :)
> >> 
> >> Well: quite the same using inject:
> >> 
> >> arr.inject(Hash.new(0)) {|h,e| h[e]+= 1; h}
> >> 
> >> It all depends on what you call 'one-line' :o)
> >> 
> >> Cheers,
> > 
> > Wow, Inject is cool method, thanks !
> > In my mind one-line is that dows not have semi-coloms or new lines of
> > course
> 
> Soo... that has a semi-colon and isn't then a one-liner?? ;-)

If that really bothers anyone...

Hash.new(0).tap{|h| arr.each{|e| h[e] += 1} }