Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
class method
ENV.invert
ENV.invert → hash of value/name pairs
hash.c
View on GitHub ↗
static VALUE
env_invert(VALUE _)
{
return rb_hash_invert(env_to_hash());
}
Returns a Hash whose keys are the ENV values, and whose values are the corresponding ENV names:
Example
ENV.replace('foo' => '0', 'bar' => '1') ENV.invert # => {"1"=>"bar", "0"=>"foo"}
For a duplicate ENV value, overwrites the hash entry:
Example
ENV.replace('foo' => '0', 'bar' => '0') ENV.invert # => {"0"=>"foo"}
Note that the order of the ENV processing is OS-dependent, which means that the order of overwriting is also OS-dependent. See About Ordering.