
Security News
Nx npm Packages Compromised in Supply Chain Attack Weaponizing AI CLI Tools
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Check if an environment variable is set to an enabled or disabled value.
Fetch an environment variable as an Array of String
s or Symbol
s.
enabled?
/disabled?
Set an environment variable:
export VARIABLE_NAME=1 # enabled
export VARIABLE_NAME=true # enabled
export VARIABLE_NAME=0 # disabled
export VARIABLE_NAME=false # disabled
And check if it's enabled or disabled:
require "$ENV"
enable_foo if $ENV.enabled?("VARIABLE_NAME")
disable_foo if $ENV.disabled?("VARIABLE_NAME")
Note that if the environment variable is not set enabled?
and disabled?
can both be false
.
If something is not enabled that does not mean it was explicitly disabled.
Don't do this:
if !$ENV.enabled?("VARIABLE_NAME")
if !$ENV.disabled?("VARIABLE_NAME")
Do this:
if $ENV.disabled?("VARIABLE_NAME")
if $ENV.enabled?("VARIABLE_NAME")
$ENV::W
Return an environment variable's value as an Array
of words (String
s):
export VARIABLE_NAME="a,b,c"
export ANOTHER_VARIABLE=
Then in Ruby:
$ENV::W["VARIABLE_NAME"] # ["a", "b", "c"]
$ENV::W["ANOTHER_VARIABLE"] # []
# Or
$ENV.W("VARIABLE_NAME") # ["a", "b", "c"]
$ENV.w("VARIABLE_NAME") # ["a", "b", "c"]
Mnemonic %w(a b c)
.
$ENV::I
Return an environment variable's value as an Array
of Symbol
s:
$ENV::I["VARIABLE_NAME"] # [:a, :b, :c]
# Or
$ENV.I("VARIABLE_NAME") # [:a, :b, :c]
$ENV.i("VARIABLE_NAME") # [:a, :b, :c]
Mnemonic %w(a b c)
.
ENV
p $ENV["VARIABLE_NAME"]
p $ENV.delete("VARIABLE_NAME")
$ENV.each { |name, value| ... }
$ENV
require "env_var"
enable_foo if EnvVar.enabled?("VARIABLE_NAME")
disable_foo if EnvVar.disabled?("VARIABLE_NAME")
p EnvVar["VARIABLE_NAME"]
p EnvVar.delete("VARIABLE_NAME")
EnvVar.each { |name, value| ... }
require "env_var/env"
enable_foo if ENV.enabled?("VARIABLE_NAME")
disable_bar if ENV.disabled?("VARIABLE_NAME")
p ENV::i["VARIABLE_NAME"]
p ENV::w["VARIABLE_NAME"]
# ENV::W, ENV::I do not work
Got tired of writing this over and over in various applications:
enable_foo if %w[true 1 on].include?(ENV["ENABLE_FOO"])
Skye Shaw (skye DOT shaw AT gmail )
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that env_var demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.