Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

ruby
env
include
communitycreator

What is the ENV.include?() method in Ruby?

okwudili onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

Overview

The ENV.include?() method in Ruby lets us check if a certain environment name is present in our environment variables. It returns a Boolean value.

Syntax

ENV.include?(name)
Syntax to check if a certain environment variable exists

Parameters

name: This is the name of the environment variable whose existence we want to check.

Return value

This method returns a Boolean value. If the environment variable exists, it returns a true value. Otherwise, it returns a false value.

Code example

# Creating some environment variables
ENV["name"] = "Ruby"
ENV["platform"] = "Edpresso"
ENV["user_secret"] = "23423lsdfksld23"
# Checking if some keys exist
puts ENV.include?("name")
puts ENV.include?("platform")
puts ENV.include?("admin_secret")
Checking if a certain environment variable exists

Explanation

  • Lines 2–4: We create some environment variables.
  • Lines 7–9: We check if the environment variables exist. Then, we print the values to the console.

RELATED TAGS

ruby
env
include
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring