Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

ENV.shift

ENV.shift → [name, value] or nil

Removes the first environment variable from ENV and returns a 2-element Array containing its name and value:

Example
ENV.replace('foo' => '0', 'bar' => '1')
ENV.to_hash # => {'bar' => '1', 'foo' => '0'}
ENV.shift # => ['bar', '1']
ENV.to_hash # => {'foo' => '0'}

Exactly which environment variable is “first” is OS-dependent. See About Ordering.

Returns nil if the environment is empty.

See also .select! .size .select .slice also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1