Skip to content

Instantly share code, notes, and snippets.

@bjallen
Created July 6, 2012 13:13
Show Gist options
  • Save bjallen/3060086 to your computer and use it in GitHub Desktop.
Save bjallen/3060086 to your computer and use it in GitHub Desktop.
playing with overriding hash and equals
class Point
attr_accessor :lat, :lon, :title, :content
def initialize(lat, lon, title, content)
@lat = lat
@long = lon
@title = title
@content = content
end
def ==(other)
other.hash == self.hash
end
alias :eql? :==
def hash
self.lat.hash + self.lon.hash + self.title.hash
end
end
points = []
points << Point.new(1,2,'airport','lax')
points << Point.new(10,20,'airport','dfw')
points << Point.new(1,2,'airport','lax')
points << Point.new(100,200,'airport','akl')
points.uniq!
puts points.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment