Skip to content
instance method

Hash#key

(V) -> K?
key(value) → key or nil

Returns the key for the first-found entry with the given value (see Entry Order):

Example
h = {foo: 0, bar: 2, baz: 2}
h.key(0) # => :foo
h.key(2) # => :bar

Returns nil if no such value is found.

Related: see Methods for Fetching.

See also #key? #keep_if #invert #keys also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0