gpt4 book ai didi

ruby-on-rails - Rails.env 与 RAILS_ENV

转载 作者:行者123 更新时间:2023-12-03 04:09:32 25 4
gpt4 key购买 nike

在检查正在运行的环境时,我在示例中看到了这两种情况。首选什么?无论出于何种意图和目的,它们都是平等的吗?

最佳答案

According to the docs , #Rails.env 包装 RAILS_ENV:

    # File vendor/rails/railties/lib/initializer.rb, line 55
def env
@_env ||= ActiveSupport::StringInquirer.new(RAILS_ENV)
end

但是,具体看看它是如何包装的,使用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?

所以它们并不完全等同,但相当接近。我还没有太多使用 Rails,但我想说,由于使用了 StringInquirer#Rails.env 无疑是更具视觉吸引力的选项。

关于ruby-on-rails - Rails.env 与 RAILS_ENV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2715035/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com