我有一个脚本需要从项目Gemfile中定义的宝石中获取特定文件。
AtomicInteger value = new AtomicInteger(0);
Integer anotherCalculatedValue = ...;
value.getAndAccumulate(anotherCalculatedValue, Math::max);
当我运行脚本时,出现无法加载#!/usr/bin/env ruby
require 'some_gem/helpers/some_helper'
... rest of script
的错误。如果我与some_helper.rb
一起运行,那么一切正常
我知道bundle exec将Gems暴露给$ LOAD_PATH,让bundle exec command...
工作。有没有办法将该功能移到脚本中,这样用户就不必键入require
?
在我需要gem文件之前,我是否只需要在脚本中添加bundle exec
?
答案 0 :(得分:1)
http://bundler.io/v1.12/#getting-started
:)
#!/usr/bin/env ruby
require 'rubygems' # because reasons.. most probably it is not needed unless you are using really old ruby where it is not loaded by default
# also at the moment rubygems and bundler are being merged :)
require 'bundler/setup' # for things installed with bundler
require 'some_gem/helpers/some_helper'