We use the size
property of the ENV
class in Ruby to return the count of environment variables present. It is similar to the length
property.
ENV.size
The value returned is an integer that represents the total number of environment variables present.
# get size of default variablesputs "#{ENV.size}" # 6# clear all environment variablesENV.clear# get size of current variablesputs "#{ENV.size}" # 0# create some environment variablesENV["secret_name"] = "secret"ENV["secret_token"] = "secret"ENV["private_key"] = "code_sync_456"ENV["foo"] = "123"ENV["bar"] = "123"# reprint size of environment variablesputs "#{ENV.size}" # 5
clear
method.size
property to print the number of environment variables to the console.