Skip to content

Instantly share code, notes, and snippets.

@atton
Created March 18, 2015 12:53
Show Gist options
  • Save atton/ea9178765cf4fcdfcc83 to your computer and use it in GitHub Desktop.
Save atton/ea9178765cf4fcdfcc83 to your computer and use it in GitHub Desktop.
hash keys
#!/usr/bin/env ruby
=begin
[30] pry(main)> a.class.ancestors
=> [Twitter::NullObject,
Twitter::NullObject::Customizations,
Comparable,
Twitter::NullObject::GeneratedMethods,
Naught::NullObjectTag,
Naught::Conversions,
Naught::BasicObject,
BasicObject]
=end
hash = {}
class NotHasHashMethod < BasicObject
end
class HasHashMethod < BasicObject
def hash
:dummy # not has to_int
end
end
hash[NotHasHashMethod.new] = 100 # => undefined method `hash' for #<NotHasHashMethod:0x007f8201886c80> (NoMethodError)
hash[HasHashMethod.new] = 200 # => no implicit conversion of Symbol into Integer (TypeError)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment