From: Robert Klemme Date: 2008-07-03T21:13:53+09:00 Subject: Re: thoughts on a more generic Array#partition function 2008/7/3 Rick DeNatale : > On Thu, Jul 3, 2008 at 12:53 AM, Peņa, Botp wrote: > >> From: Rudi Cilibrasi [mailto:cilibrar@gmail.com] >> # h = a.group_by() { |i| func(i) } >> # h.keys.sort.map { |k| h[k] } >> # This is not so bad, but perhaps has a small disadvantage that it >> # requires eql? and hash methods defined unlike npartition. But I >> # cannot figure out a simpler version to get array of array's output. >> >> just apply #values to it, >> > > Not exactly the same, values doesn't guarantee the desired ordering by key. That's easily fixed: arbitrary_hash.sort_by {|k,| k}.map {|k,v| v} Having said that the #group_by implementation seems the more general solution (because of less requirements, i.e. keys do not need to provide <=>). Kind regards robert -- use.inject do |as, often| as.you_can - without end