From: Daniel Berger Date: 2005-01-27T01:15:47+09:00 Subject: Re: Array::uniq { block } ? 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