From: Joel VanderWerf Date: 2008-01-08T02:20:16+09:00 Subject: Re: compact or uniq that takes a block like sort? Pit Capitain wrote: > 2008/1/7, Bil Kleb : >> I'm looking for an elegant way to do the following: >> (...) > > Bil, this makes the test pass: > > class Array > def consolidate > Hash[*flatten].sort > end > end That certainly is elegant! Maybe Bil wanted to preserve the monotonicity? class Array def consolidate Hash[*flatten].sort_by {|x,y| y} end end p [ [5,1] , [3,2] ].consolidate # ==> [[5, 1], [3, 2]] -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407