Rails.env vs RAILS_ENV

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)

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:


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.

Leave a Comment