Ruby's ENV object gives you access to environment variables. It looks like normal Ruby hash:
ENV["TERM"] #=> "xterm"
ENV["SOMETHING"] = "NEW" #=> "NEW"
But this is only the surface. Turns out ENV
is a special object:
ENV.class #=> Object
It is hash-like, but lacks some functionality:
ENV.flatten # NoMethodError
ENV.default = "MyNullObject" # NoMethodError
Besides this, it behaves like an ordinary hash:
ENV["my_value"] = "something"
ENV[42] = "oops" # not quite: TypeError
Another thing that is missing: Merging the ENV
hash with another hash:
ENV.merge(Idiosyncratic: "YES") # NoMethodError
Resources
More Idiosyncratic Ruby
- Please Comment on GitHub
- Next Article: Regular Extremism
- Previous Article: Globalization