The replace()
method replaces all the environment variables present. It is similar to the clear
method. It replaces all variables with new environment variables that it takes as a Hash. This Hash is the parameter that it takes.
ENV.replace(hash)
hash
: This is a hash that is passed to the replace()
method. The name/value pairs of this hash replace all the environment variables present.
The value returned is the ENV.
# print current environment variablesputs "PREVIOUS ENVIRONMENT VARIABLES: \n"ENV.each_pair{|name, value| puts "#{name} = #{value}"}# replace all environment variables with replace()ENV.replace("c" => "cat", "token" => "123", "secret" => "323dsdf")# reprint all environment variablesputs "\nCURRENT ENVIRONMENT VARIABLES: \n"ENV.each_pair{|name, value| puts "#{name} = #{value}"}
each_pair{}
method and print the current environment variables.replace()
method and replace all environment variables present with new ones.