Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

class method

ENV.values_at

ENV.values_at(*names) → array of values

Returns an Array containing the environment variable values associated with the given names:

Example
ENV.replace('foo' => '0', 'bar' => '1', 'baz' => '2')
ENV.values_at('foo', 'baz') # => ["0", "2"]

Returns nil in the Array for each name that is not an ENV name:

Example
ENV.values_at('foo', 'bat', 'bar', 'bam') # => ["0", nil, "1", nil]

Returns an empty Array if no names given.

Raises an exception if any name is invalid. See Invalid Names and Values.

See also .values .value? also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0