Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Hash#hash

hash.hash → an_integer

Returns the Integer hash-code for the hash.

Two Hash objects have the same hash-code if their content is the same (regardless or order):

Example
h1 = {foo: 0, bar: 1, baz: 2}
h2 = {baz: 2, bar: 1, foo: 0}
h2.hash == h1.hash # => true
h2.eql? h1 # => true
See also #flatten #has_key? #filter! #has_value? also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0