我想创建一个新的Ruby应用程序,所以我决定使用bundle gem foo
来完成它。这给了我整体:
lib/
foo/
version.rb
foo.rb
Gemfile
Rakefile
foo.gemspec
README.md
结构。现在,当我运行ruby foo.rb
时,我得到:
`require': cannot load such file -- foo/version (LoadError)
foo.rb只是默认值:
require 'foo/version'
module Foo
end
宝石可以不靠自己跑吗?我希望我不必将我的宝石包含在示例应用程序中,只是为了测试它?
答案 0 :(得分:6)
您需要运行bundle exec ruby foo.rb
才能使用捆绑的宝石。
或者,您可以修改foo.rb
本身以假设Bundler。只需加上
require 'bundler/setup'
在顶部。
答案 1 :(得分:0)
你从哪个目录运行?我会检查你的$ LOAD_PATH并确保包含lib。