From: Martin DeMello Date: 2005-01-31T21:55:53+09:00 Subject: Re: Array::uniq { block } ? Robert Klemme wrote: > module Enumerable > def uniq_by > h = {}; inject([]) {|a,x| h[yield(x)] ||= a << x} > end > end > > >> a.uniq_by {|x| x%3} > => [2, 7, 9] > > Beautiful about this version is that it does not need the "; h" at the end > of the inject block and no ".values", too... :-) Very nice indeed. martin