From: itsme213 Date: 2005-01-27T03:55:47+09:00 Subject: Re: Array::uniq { block } ? I agree, #uniq is certainly not the only candidate. I think it would be very useful to compile a list of all such methods that could use a block to override some default internal method (#== in the case of uniq), and consider these for 2.0. "Daniel Berger" wrote in message news:1106756045.223279.94600@f14g2000cwb.googlegroups.com... > Belorion wrote: > > I have an array of arrays. I want to be able to do a uniq operation > > on my array, and have it accept a block so I can specify what to > > examine for uniqueness. For example, in IRB > > > > a = [ [1,2], [3,4], [1,3] ] > > a.sort { |x,y| x[0] <=> y[0] } > > > > returns => [ [1,2], [1,3], [3,4] ] > > > > However, it does not appear uniq accepts blocks: > > > > a = [ [1,2], [3,4], [1,3] ] > > a.uniq { |x,y| x[0] == y[0] } > > > > returns => [ [1,2], [3,4], [1,3] ] > > and a.uniq! with the above block returns nil. > > > > Am I stuck writing my own deep_uniq? Granted, it would be hard, but > > certainly not as clean as the above. > > Not that this is a bad idea, but why do I get this feeling that we're > eventually going to find an excuse to allow blocks to virtually every > method in the core library? > > Where does it all end?! > > Dan >