We use the ENV
class to store environment variables. These environment variables can be secrets and configurations we want to keep private. We can check if all these variables are empty by using the empty?
property.
ENV.empty?
The empty?
function returns true
when there are no environment variables. Otherwise, it returns false
.
The following piece of code completes the picture and shows the example with its output:
# create some environment variables ENV["payment_key"] = "323selfdsd34" ENV["authorization_key"] = "123456788" # check if ENV is empty puts ENV.empty? # false # print all environment variables ENV.each_pair{|name, value| puts "#{name} = #{value}"} # clear all variables ENV.clear # check if ENV is empty puts ENV.empty? # true
ENV
is empty.each_pair{}
method that gives us access to each environment variable name and value.clear
method.ENV
is empty once more.RELATED TAGS
CONTRIBUTOR
View all Courses