The length of environment variables is the total number of all environment variables present. In other words, this is the count of all environment variables. We can use the length
property to get this number.
ENV.length
The value returned is an integer that represents the number of environment variables present.
# Getting the length of default variables puts "#{ENV.length}" # 6 # Clearing all environment variables ENV.clear # Getting the length of current variables puts "#{ENV.length}" # 0 # Creating some environment variables ENV["secret_name"] = "secret" ENV["secret_token"] = "secret" ENV["private_key"] = "code_sync_456" ENV["foo"] = "123" ENV["bar"] = "123" # Reprinting the length of environment variables puts "#{ENV.length}" # 5
clear
method.RELATED TAGS
CONTRIBUTOR
View all Courses