我需要从普通的ruby脚本引用本地gem,而不需要安装gem。在路上 如何在红宝石中引用本地宝石?,我尝试使用以下设置创建Gemfile:
%w(
custom_gem
another_custom_gem
).each do |dependency|
gem dependency, :path => File.expand_path("../../#{dependency}", __FILE__)
end
并且脚本如下所示:
require 'custom_gem'
CustomGem::Do.something
当我执行此操作时:
bundle exec ruby script.rb
我明白了:
script.rb:1:in `require': cannot load such file -- custom_gem (LoadError) from script.rb:1:in `<main>'
如果我遗漏了 require 'custom_gem'
,我得到:
script.rb:3:in `<main>': uninitialized constant CustomGem (NameError)
我甚至试过没有捆绑,只是写作 gem ... :path =>̣ ...
在脚本本身,但没有结果。有没有其他方法可以从ruby脚本引用自定义gem,而无需在本地安装gem?