【发布时间】:2021-02-19 23:05:31
【问题描述】:
我正在使用dotenv Gem 来读取我的 .env 文件中的变量。我创建了一个更新 .env 文件的控制台命令,但也在同一运行时中读取它们。问题是它读取旧值,即使我更新了 .env 文件。有没有办法在运行时刷新 ENV 以获取最新值?
.env
FOOBAR=hello
ruby.rb
puts ENV['FOOBAR'] # Prints "hello"
EnvFile.update_variable('.env', 'FOOBAR', "How are you?")
Dotenv.load('.env')
puts ENV['FOOBAR'] # Prints "hello" even though looking in .env it has the new value "How are you?"
【问题讨论】: