Created
January 15, 2016 18:24
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 Foo | |
include Comparable | |
attr_accessor :x, :y, :z | |
def initialize(x,y,z) | |
@x, @y, @z = x,y,z | |
end | |
def <=>(other) | |
x == other.x && | |
y == other.y && | |
z == other.z | |
end | |
end | |
f1 = Foo.new(1,2,3) | |
f2 = Foo.new(1,2,3) | |
f3 = Foo.new(2,3,4) | |
p f1 == f2 | |
p f1 == f3 | |
# compare_test.rb:21: warning: Comparable#== will no more rescue exceptions of #<=> in the next release. | |
# compare_test.rb:21: warning: Return nil in #<=> if the comparison is inappropriate or avoid such comparison. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment