Skip to content

Instantly share code, notes, and snippets.

@wallace
Last active August 29, 2015 14:04
Show Gist options
  • Save wallace/4a0d0f0403a2b85b383f to your computer and use it in GitHub Desktop.
Save wallace/4a0d0f0403a2b85b383f to your computer and use it in GitHub Desktop.
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