instance method
Array#rassoc
(untyped) -> ::Array[untyped]?
rassoc(object) → found_array or nil
array.c
View on GitHub ↗
VALUE
rb_ary_rassoc(VALUE ary, VALUE value)
{
long i;
VALUE v;
for (i = 0; i < RARRAY_LEN(ary); ++i) {
v = rb_check_array_type(RARRAY_AREF(ary, i));
if (RB_TYPE_P(v, T_ARRAY) &&
RARRAY_LEN(v) > 1 &&
rb_equal(RARRAY_AREF(v, 1), value))
return v;
}
return Qnil;
}
Returns the first element ele in self such that ele is an array and ele[1] == object:
Example
a = [{foo: 0}, [2, 4], [4, 5, 6], [4, 5]] a.rassoc(4) # => [2, 4] a.rassoc(5) # => [4, 5, 6]
Returns nil if no such element is found.
Related: Array#assoc; see also Methods for Fetching.