Ruby Newbie homepage Ruby Newbie homepage

How to use

Quick guide

Official content
Returns the key for the first-found entry with the given value (see Entry Order):
h = {foo: 0, bar: 2, baz: 2}
h.key(0) # => :foo
h.key(2) # => :bar
Returns nil if so such value is found.
 
               static VALUE
rb_hash_key(VALUE hash, VALUE value)
{
    VALUE args[2];

    args[0] = value;
    args[1] = Qnil;

    rb_hash_foreach(hash, key_i, (VALUE)args);

    return args[1];
}
            

Was this page useful?