Skip to content

Instantly share code, notes, and snippets.

@jacegu
Created January 14, 2012 15:47
Show Gist options
  • Save jacegu/1611838 to your computer and use it in GitHub Desktop.
Save jacegu/1611838 to your computer and use it in GitHub Desktop.
class Key
attr_reader :value
def initialize(value)
@value = value
end
def eql?(other_key)
value == other_key.value
end
def hash
value.hash
end
end
k1 = Key.new('foo')
k2 = Key.new('foo')
h = { k1 => 'bar' }
puts h.has_key? k1 # -> true
puts h.has_key? k2 # -> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment