Skip to content
class method

ENV.key

ENV.key(value) → name or nil

Returns the name of the first environment variable with value, if it exists:

Example
ENV.replace('foo' => '0', 'bar' => '0')
ENV.key('0') # => "foo"

The order in which environment variables are examined is OS-dependent. See About Ordering.

Returns nil if there is no such value.

Raises an exception if value is invalid:

Example
ENV.key(Object.new) # raises TypeError (no implicit conversion of Object into String)

See Invalid Names and Values.

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