Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

class method

ENV.reject

ENV.reject { |name, value| block } → hash of name/value pairs
ENV.reject → an_enumerator

Yields each environment variable name and its value as a 2-element Array. Returns a Hash whose items are determined by the block. When the block returns a truthy value, the name/value pair is added to the return Hash; otherwise the pair is ignored:

Example
ENV.replace('foo' => '0', 'bar' => '1', 'baz' => '2')
ENV.reject { |name, value| name.start_with?('b') } # => {"foo"=>"0"}

Returns an Enumerator if no block given:

Example
e = ENV.reject
e.each { |name, value| name.start_with?('b') } # => {"foo"=>"0"}
See also .reject! .rehash .rassoc .replace also in 4.1 · 4.0 · 3.3 · 3.2 · 3.1 · 3.0