Skip to content
class method

ENV.include?

ENV.include?(name) → true or false
ENV.has_key?(name) → true or false
ENV.member?(name) → true or false
ENV.key?(name) → true or false

Returns true if there is an environment variable with the given name:

Example
ENV.replace('foo' => '0', 'bar' => '1')
ENV.include?('foo') # => true

Returns false if name is a valid String and there is no such environment variable:

Example
ENV.include?('baz') # => false

Returns false if name is the empty String or is a String containing character '=':

Example
ENV.include?('') # => false
ENV.include?('=') # => false

Raises an exception if name is a String containing the NUL character "\0":

Example
ENV.include?("\0") # Raises ArgumentError (bad environment variable name: contains null byte)

Raises an exception if name has an encoding that is not ASCII-compatible:

Example
ENV.include?("\xa1\xa1".force_encoding(Encoding::UTF_16LE))
# Raises ArgumentError (bad environment variable name: ASCII incompatible encoding: UTF-16LE)

Raises an exception if name is not a String:

Example
ENV.include?(Object.new) # TypeError (no implicit conversion of Object into String)
See also .has_value? .inspect .has_key? .invert also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0