Trans <transfire / gmail.com> wrote: > > Has anyone, could anyone, write a Ruby version of this method? I'm not > sure what its supposed to do exaclty. Id like to see source. module Enumerable def uniq_by(*args, &blk) blk = lambda {|i| i.send(*args)} unless args.empty? raise "needs args or block" unless blk h = {} a = [] each {|i| k = blk.call(i) a << i unless h[k] h[k] = true } a end end p (-5..5).to_a.uniq_by {|i| i*i} p [[1, 2], [3, 4], [5, 6], [7, 2]].uniq_by(:at, 1) martin