Skip to content

Instantly share code, notes, and snippets.

@Mon-Ouie

Mon-Ouie/uniq.rb Secret

Created June 3, 2012 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mon-Ouie/474a748e291b43125142 to your computer and use it in GitHub Desktop.
Save Mon-Ouie/474a748e291b43125142 to your computer and use it in GitHub Desktop.
class NotWorking
include Comparable
def initialize(obj)
@attr = obj
end
attr_accessor :attr
def <=>(other)
if other.is_a? NotWorking
attr <=> other.attr
end
end
end
class Working < NotWorking
alias eql? ==
def hash
attr.hash
end
end
p [NotWorking.new("foo"), NotWorking.new("bar"),
NotWorking.new("foo")].uniq.size # 3
p [Working.new("foo"), Working.new("bar"),
Working.new("foo")].uniq.size # 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment