Know your Environment

Ruby's ENV object gives you accss to enviroment variables. It looks like normal Ruby hash:

ENV["TERM"] #=> "xterm"

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


More Idiosyncratic Ruby