From: Robert Klemme Date: 2008-09-09T18:36:34+09:00 Subject: Re: Is this a sensible implementation for Array#group_by ? 2008/9/9 Max Williams : > Adam Shelley wrote >> I think the Facets library already has a similar method. > > Erik Veenstra wrote: >> Indeed, Facets does have an Enumerable#group_by. And it has an >> Enumerable#cluster_by as well. And the latter is the one you're >> looking for, because you want an Array and not a Hash. > > Facets - investigates again... now that is *very* good indeed. Wow. I > had a feeling this would exist already in a better form :) If I would want to do it myself, then I'd probably do module Enumerable def group_by result = Hash.new {|h,k| h[k] = []} each {|el| result[yield el] << el} result end end Kind regards robert -- use.inject do |as, often| as.you_can - without end