-
-
Save Mon-Ouie/474a748e291b43125142 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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