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
hash.c
View on GitHub ↗
static VALUE
rb_hash_rassoc(VALUE hash, VALUE obj)
{
VALUE args[2];
args[0] = obj;
args[1] = Qnil;
rb_hash_foreach(hash, rassoc_i, (VALUE)args);
return args[1];
}
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.