有没有人足够了解 Ruby 的 require
来告诉我以下语法是否有效:
class Something
def initialize(mode)
case mode
when :one then require 'some_gem'
when :two then require 'other_gem'
end
end
end
s = Something.new
如果是这样,需要
将 gem 放入全局命名空间,就像在文件顶部时一样?
最佳答案
If so, would the require place the gem into the global namespace as the same require at the top of the file would?
是的。 require
没有范围,而 load
有。
关于ruby - 动态需要文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2230512/