instance method
Hash#rassoc
(V) -> [ K, V ]?
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];
}
Searches self for the first entry whose value is == to the given value; see Entry Order.
If the entry is found, returns its key and value as a 2-element array; returns nil if not found:
Example
h = {foo: 0, bar: 1, baz: 1} h.rassoc(1) # => [:bar, 1]
Related: see Methods for Fetching.