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

Array#rassoc

array.rassoc(obj) → found_array or nil

Returns the first element in self that is an Array whose second element == obj:

Example
a = [{foo: 0}, [2, 4], [4, 5, 6], [4, 5]]
a.rassoc(4) # => [2, 4]

Returns nil if no such element is found.

Related: assoc.

See also #push #reject #product #reject! also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0