The to_a
method can be used to return the environment variable class, ENV, to an array. It returns an array containing the name/value pairs of each environment variable.
ENV.to_a
None.
An array that contains objects of two attributes is returned, with a name/value pair for each.
# clear all 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"# reprint length of environment variablesputs "#{ENV.to_a}"
to_a
method, we were able to get the array containing 2-element arrays of name/value pair of each environment variable. And then we printed our result.