Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. 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.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0