On Fri, May 14, 2010 at 12:47 PM, Toby Rodwell <trodwell / iee.org> wrote:

ah a #unique_by, I therefore conclude that you want to keep one
element with the given property.

module Enumerable
  def unique_by &blk
    keys = {}
    reject{ | ele |
      key = blk[ele]
      keys[key].tap{ keys[key]=true }
    }
  end
end

p [*1..10].unique_by{ |x| x % 3 }

Could'nt come up with something more concise :(
HTH
R.


-- 
The best way to predict the future is to invent it.
-- Alan Kay