From: Dave Thomas Date: 2008-02-07T11:46:20+09:00 Subject: Re: Array Practice On Feb 6, 2008, at 8:15 PM, Christopher Dicely wrote: > Anytime I want to "build up" something from an existing Enumerable > object (Array, etc.) in Ruby, I usually look to inject or collect; the > most elegant of the way I've come up with of doing exactly what you > want uses ==, *, uniq, collect, find_all, and size, and the function > body fits on a single line without semi-colons. (I'm not holding up > that it is a one-liner as a strength, just as a description.) Ruby 1.9 lets you do it with a few less methods... (I'll give it away because I'm fairly sure the OP won't be using 1.9). Of course, it only works on immediate values... [1,2,3,1,2,2,4,3,2,1].group_by(&:object_id).values Cheers Dave