Array#uniq_by
require "set" class Array def uniq_by seen = Set.new select do |x| this = yield(x) if seen.include?(this) next(false) else seen.add(this) next(true) end end end end