Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

ENV.keys

ENV.keys → array of names

Returns all variable names in an Array:

Example
ENV.replace('foo' => '0', 'bar' => '1')
ENV.keys # => ['bar', 'foo']

The order of the names is OS-dependent. See About Ordering.

Returns the empty Array if ENV is empty.

See also .key? .length .key .member? also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0