Skip to content

Instantly share code, notes, and snippets.

View denisdefreyne's full-sized avatar

Denis Defreyne denisdefreyne

View GitHub Profile
class Employee
# …
def hash
[self.class, @id].hash
end
end
class Path
# …
def hash
[self.class, @components].hash
end
end
class Point
# …
def hash
[self.class, @x, @y].hash
end
end
class Path
# …
def ==(other)
other.respond_to?(:to_str) &&
to_str == other.to_str
end
def eql?(other)
self.class == other.class &&
@components == other.components
class Employee
# …
def ==(other)
self.eql?(other)
end
end
class Point
# …
def ==(other)
self.eql?(other)
end
end
1 == 1.0 # => true
1.eql?(1.0) # => false
1.0.eql?(1.0) # => true
"foo" == "foo" # => true
"foo".eql?("foo") # => true
"foo".eql?("bar") # => false
class Employee
# …
def ==(other)
self.equal?(other) || (
# …
)
end
end
class Employee
# …
def ==(other)
super || (
self.class == other.class &&
[email protected]? &&
@id == other.id
)
end
end