🕷 zenspider.com

by ryan davis



sitemap
Looking for the Ruby Quickref?

Enumerable#uniq_by

Published 2012-01-18 @ 11:00

Tagged ruby, thoughts, toys

Random code sitting around waiting to be blogged…

1
2
3
4
5
6
7
8
9
10
11
12
module Enumerable
  def uniq_by
    r, s = [], {}
    each do |e|
      v = yield(e)
      next if s[v]
      r << e
      s[v] = true
    end
    r
  end
end