Skip to content

Instantly share code, notes, and snippets.

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