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
hash.c
View on GitHub ↗
static VALUE
rb_f_getenv(VALUE obj, VALUE name)
{
const char *nam = env_name(name);
VALUE env = getenv_with_lock(nam);
return env;
}
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.