Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Hash#==
(untyped other) -> bool
self == other → true or false
hash.c
View on GitHub ↗
static VALUE
rb_hash_equal(VALUE hash1, VALUE hash2)
{
return hash_equal(hash1, hash2, FALSE);
}
Returns whether all of the following are true:
-
otheris aHashobject (or can be converted to one). -
selfandotherhave the same keys (regardless of order). -
For each key
key,self[key] == other[key].
Examples:
Example
h = {foo: 0, bar: 1} h == {foo: 0, bar: 1} # => true # Equal entries (same order) h == {bar: 1, foo: 0} # => true # Equal entries (different order). h == 1 # => false # Object not a hash. h == {} # => false # Different number of entries. h == {foo: 0, bat: 1} # => false # Different key. h == {foo: 0, bar: 2} # => false # Different value.
Related: see Methods for Comparing.