Last active
November 21, 2019 06:54
-
-
Save higaki/129f8f43187e4f2f29b1efcb524d6989 to your computer and use it in GitHub Desktop.
This file contains 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
RUBY_VERSION # => "2.7.0" | |
"a".hash # => -4127323257193555845 | |
"b".hash # => -2092951289148142958 | |
"foo".hash # => -4298047480057265190 | |
"bar".hash # => 4242949873151017721 | |
h = {"foo" => 0} | |
h["foo"] # => 0 | |
h["bar"] # => nil | |
class String | |
alias_method("original_hash", "hash") | |
def hash | |
case self | |
when "foo" then -1 | |
when "bar" then -1 | |
else original_hash | |
end | |
end | |
end | |
"a".hash # => -4127323257193555845 | |
"b".hash # => -2092951289148142958 | |
"foo".hash # => -1 | |
"bar".hash # => -1 | |
"foo".hash == "bar".hash # => true | |
h = {"foo" => 0} | |
h["foo"] # => 0 | |
h["bar"] # => nil | |
"foo".eql? "foo" # => true | |
"foo".eql? "bar" # => false | |
"bar".eql? "foo" # => false | |
"bar".eql? "bar" # => true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment