From: Pit Capitain Date: 2005-01-30T20:07:48+09:00 Subject: Re: Array::uniq { block } ? Trans schrieb: > 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. No problem: require 'set' class Array def uniq_by result = [] values = Set.new each do |elem| value = yield elem unless values.include? value values << value result << elem end end result end end p ( 0 .. 9 ).to_a.uniq_by { |x| x % 4 } # => [0, 1, 2, 3] I bet Robert will transform this into a version using inject ;-) Regards, Pit