Rails.env vs RAILS_ENV
ruby-on-rails
Solution
According to the docs, `#Rails.env` wraps `RAILS_ENV`:
# File vendor/rails/railties/lib/initializer.rb, line 55
def env
@_env ||= ActiveSupport::StringInquirer.new(RAILS_ENV)
end
But, look at specifically how it's wrapped, using `ActiveSupport::StringInquirer`:
Wrapping a string in this class gives you a prettier way to test for equality. The value returned by Rails.env is wrapped in a StringInquirer object so instead of calling this:
Rails.env == "production"
you can call this:
Rails.env.production?
So they aren't exactly equivalent, but they're fairly close. I haven't used Rails much yet, but I'd say `#Rails.env` is certainly the more visually attractive option due to using `StringInquirer`.
Problem
I see both in examples when checking what env one is running in. What's preferred? Are they, for all intents and purposes equal?