The to_h
method can be used to convert the ENV
, which contains all environment variables, into a hash. A hash contains key-value pairs.
ENV.to_h
None.
The value returned is a hash containing each environment variable in the form of key/value pairs.
# clear default environment variablesENV.clear# create some environment variablesENV["secret_name"] = "secret"ENV["secret_token"] = "secret"ENV["private_key"] = "code_sync_456"ENV["foo"] = "123"ENV["bar"] = "123"# convert to hashourHash = ENV.to_h# print new hashputs ourHashputs ourHash.class
ourHash
.to_h
to create the type of class and print it to the console.