From: Sigurd Date: 2012-01-17T01:09:28+09:00 Subject: Re: uniq with count; better way? Well it's one of the possible solutions. You example is not accurate though: 5 + [1, 2, 3, 4].reduce(&:+) On Jan 16, 2012, at 6:04 PM, Adam Prescott wrote: > On Mon, Jan 16, 2012 at 16:00, Sigurd wrote: > >> [4,5,6,4,5,6,6,7].inject(Hash.new(0)) {|res, x| res[x] += 1; res } >> > > I think this is a misuse of inject, personally, every time I see it. It's > harder to read and it doesn't give the feeling of actually "reducing" > (inject's alias) the array down to one thing. The required `; res` is a > sign of that. Compare: > > [1, 2, 3, 4].inject(5) { |a, b| a + b }