在检查正在运行的环境时,我在示例中看到了两者.首选什么?就所有意图和目的而言,它们是否相同?
I see both in examples when checking what env one is running in. What's preferred? Are they, for all intents and purposes equal?
推荐答案根据文档,#Rails.env 包装了 RAILS_ENV:
# File vendor/rails/railties/lib/initializer.rb, line 55 def env @_env ||= ActiveSupport::StringInquirer.new(RAILS_ENV) end但是,使用 ActiveSupport::StringInquirer 来具体查看如何包装它:
But, look at specifically how it's wrapped, using ActiveSupport::StringInquirer:
在这个类中包装一个字符串给出你是一种更漂亮的测试方式平等.返回的值Rails.env 被包裹在一个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"
你可以这样称呼:
Rails.env.production?所以它们并不完全等价,但它们相当接近.我还没有经常使用 Rails,但我想说 #Rails.env 由于使用了 StringInquirer,所以在视觉上更有吸引力.
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.
更多推荐
Rails.env 与 RAILS
发布评论