The has_value?()
method in Ruby checks if a certain value of an environment variable exists. If such a value exists, this methods returns a true
Boolean value. Otherwise, it returns a false
value.
ENV.has_value?("value")
value
: This is the value whose existence we want to check as an environment variable in our system.
This method returns a Boolean value. If the value exists, it returns true
. Otherwise, it returns false
.
# Creating some environment variablesENV["G"] = "Google"ENV["N"] = "Netflix"ENV["A"] = "Apple"ENV["A"] = "Amazon"ENV["M"] = "Meta"# Checking if the values existputs ENV.has_value?("Google") # trueputs ENV.has_value?("Facebook") # falseputs ENV.has_value?("Meta") # trueputs ENV.has_value?("Blockchain") # false
has_value?()
method to check if some values exist. Then, we print the results to the console.