/*
* call-seq:
* hsh.index(value) => key
*
* Returns the key for a given value. If not found, returns <code>nil</code>.**h={"a"=>100,"b"=>200}*h.index(200)#=> "b"*h.index(999)#=> nil**/
static VALUE
rb_hash_index(hash, value)
VALUE hash, value;
{
VALUE args[2];
args[0] = value;
args[1] = Qnil;
rb_hash_foreach(hash, index_i, (st_data_t)args);
return args[1];
}
Remember that checking for a value is a potentially slow operation (all the
elements might be iterated) as oposed to querying a key (e.g. with has_key?), which is supposed to be fast in
a Hash.