Created
March 18, 2015 12:53
-
-
Save atton/ea9178765cf4fcdfcc83 to your computer and use it in GitHub Desktop.
hash keys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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