Last active
October 27, 2015 02:41
-
-
Save pinzolo/a2397739a8b5bfb0c4c5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
attr_reader :x, :y | |
def initialize(x, y) | |
@x = x | |
@y = y | |
end | |
def ==(other) | |
@x == other.x && @y == other.y | |
end | |
def to_s | |
"(#{x}, #{y})" | |
end | |
def inspect | |
to_s | |
end | |
end | |
p [Point.new(1, 1), Point.new(2, 2), Point.new(3, 3)] - [Point.new(3, 3), Point.new(1, 1)] | |
# => [(1, 1), (2, 2), (3, 3)] |
This file contains hidden or 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 | |
attr_reader :x, :y | |
def initialize(x, y) | |
@x = x | |
@y = y | |
end | |
def ==(other) | |
eql?(other) | |
end | |
def eql?(other) | |
@x == other.x && @y == other.y | |
end | |
def hash | |
@x + @y | |
end | |
def to_s | |
"(#{x}, #{y})" | |
end | |
def inspect | |
to_s | |
end | |
end | |
p [Point.new(1, 1), Point.new(2, 2), Point.new(3, 3)] - [Point.new(3, 3), Point.new(1, 1)] | |
# => [(2, 2)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment