method
index
v1_8_7_72 -
Show latest stable
- Class:
Hash
index(p1)public
Returns the key for a given value. If not found, returns nil.
h = { "a" => 100, "b" => 200 } h.index(200) #=> "b" h.index(999) #=> nil
1Note
Potentially slow operation
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.