Skip to content
instance method

Hash#==

(untyped other) -> bool
self == object → true or false

Returns whether self and object are equal.

Returns true if all of the following are true:

  • object is a Hash object (or can be converted to one).

  • self and object have the same keys (regardless of order).

  • For each key key, self[key] == object[key].

Otherwise, returns false.

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, bar: 1} # => false  # Different key.
h == {foo: 0, bar: 1} # => false  # Different value.

Related: see Methods for Comparing.

See also #<= #> #< #>= also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0