Skip to content

Instantly share code, notes, and snippets.

@higaki
Last active November 21, 2019 06:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save higaki/129f8f43187e4f2f29b1efcb524d6989 to your computer and use it in GitHub Desktop.
Save higaki/129f8f43187e4f2f29b1efcb524d6989 to your computer and use it in GitHub Desktop.
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