ENV[]
that fails silently RB-W1021ENV[]
silently fails and returns nil
when the environment variable is unset, which may cause unexpected behaviors when the developer forgets to set it. On the other hand, ENV.fetch
raises KeyError
or returns the explicitly specified default value.
ENV['DB_URL']
db_url = ENV['DB_URL']
ENV.fetch('DB_URL')
db_url = ENV.fetch('DB_URL')
# This is allowed as nil is falsey
!ENV['X']
# Calling some_method wouldn't fail silently if ENV['X'] is nil
ENV['X'].some_method