From: Martin DeMello Date: 2005-01-28T17:40:54+09:00 Subject: Re: Array::uniq { block } ? itsme213 wrote: > "Martin DeMello" wrote in message > > > A uniq_by would probably cover > > most of the use cases anyway. > > Why a different method? Is that the way it is done elsewhere? Why not > def uniq > if block_given? > ... less_efficient > else default_way > end By analogy with sort and sort_by a.uniq_by {|i| i[1]} would work like uniq, but hashing i[i] rather than i. a.uniq {|i,j| f(i,j) == true } would be the generalised method, but as noted that's O(n^2) rather than O(n). (Also I'm not sure it'd be algorithmically sound - you could introduce order dependencies with a sufficiently adversarial comparison function.) martin