Skip to content

Instantly share code, notes, and snippets.

@anuragkanungo
Last active August 29, 2015 14:06
Show Gist options
  • Save anuragkanungo/808d3a29692ea2542d67 to your computer and use it in GitHub Desktop.
Save anuragkanungo/808d3a29692ea2542d67 to your computer and use it in GitHub Desktop.
class Foo
attr_reader :x, :y
def initialize(x,y)
@x = x
@y = y
end
def ==(other)
if !self.instance_of?(other.class)
false
elsif self.equal?(other)
true
else
@x == other.x && @y == other.y
end
end
def eql?(other)
self == other
end
#Hash method is generally not required to override.
def hash
[@x,@y].hash *31
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment