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.[]

ENV[name] → value

Returns the value for the environment variable name if it exists:

Example
ENV['foo'] = '0'
ENV['foo'] # => "0"

Returns nil if the named variable does not exist.

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

See also .[]= .assoc also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0