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#rassoc

hash.rassoc(value) → new_array or nil

Returns a new 2-element Array consisting of the key and value of the first-found entry whose value is == to value (see Entry Order):

Example
h = {foo: 0, bar: 1, baz: 1}
h.rassoc(1) # => [:bar, 1]

Returns nil if no such value found.

See also #merge! #rehash #merge #reject also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0