Last active
August 29, 2015 14:04
-
-
Save wallace/4a0d0f0403a2b85b383f 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 Point | |
include Comparable | |
attr_accessor :x, :y | |
def initialize(x,y) | |
@x = x | |
@y = y | |
end | |
def <=>(other) | |
return -1 if self.x < other.x | |
return 0 if self.x == other.x && self.y == other.y | |
return 1 if self.x > other.x | |
end | |
end | |
puts "different points are different #{ Point.new(1,1) != Point.new(1,2) } " | |
puts "same points are same #{ Point.new(1,1) == Point.new(1,1) } " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment