From: "David A. Black" Date: 2009-10-02T02:05:17+09:00 Subject: Re: how do you do this --1926193751-19256517-1254416702=:17874 Content-Type: MULTIPART/MIXED; BOUNDARY="1926193751-19256517-1254416702=:17874" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --1926193751-19256517-1254416702=:17874 Content-Type: TEXT/PLAIN; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8BIT On Fri, 2 Oct 2009, Jes�s Gabriel y Gal�n wrote: > On Thu, Oct 1, 2009 at 5:20 PM, David A. Black wrote: >> Hi -- >> >> On Thu, 1 Oct 2009, Jes�s Gabriel y Gal�n wrote: > >>> %w{abc ads adfdf adfdw fefm mfekmw fmdms}.group_by {|x| x.length} >> >> It's interesting how often the need for group_by without the keys >> comes up. Meaning, in this case, to get the new arrays you'd >> ultimately do: >> >> �arr.group_by(&:length).values > > Yup, although in this case, I'm going to guess that he will either > > - Access the list of words of a specific number > - Sort the groups by length Yes, that's pretty likely. I guess to make the non-keyed version useful it would have to do some kind of automatic sorting, like you did in your example: module Enumerable def my_group_by(&block) g = group_by(&block) g.sort.map(&:last) end end or something. (I'm trying to be a good 1.9 citizen and use Symbol#to_proc, even though I still find it a bit line-noisy :-) And that wouldn't handle the specific number case, of course. Maybe it's not all that useful. David -- David A. Black, Director Ruby Power and Light, LLC (http://www.rubypal.com) Ruby/Rails training, consulting, mentoring, code review Book: The Well-Grounded Rubyist (http://www.manning.com/black2) --1926193751-19256517-1254416702=:17874-- --1926193751-19256517-1254416702=:17874--