The each_value{}
method of an ENV yields or accesses the value of each environment variable. When it yields each value, we can decide to do anything with it, such as print it, push it to an array, and so on.
ENV.each_value{|value|block}
value
: This is the value of each environment variable yielded by the each_value{}
method.
block
: This takes each value of the environment variable, value
, and allows us to do anything with it.
# create some environment variablesENV["1"] = "One"ENV["payment_key"] = "skdmj234ksdu9"ENV["token_key"] = "3234"# create an empty arrayarr = []# access each value of environment variables# and push to an arrayENV.each_value{|value| arr.push(value)}# print arrayputs "#{arr}"
arr
, that will contain all the values of every environment variable.each_value{}
method. We are able to access all values of the environment variables. Then, we push each value to the array we created previously.