Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby “require'&书信电报;创业板>';`在没有捆绑机的情况下工作?_Ruby - Fatal编程技术网

Ruby “require'&书信电报;创业板>';`在没有捆绑机的情况下工作?

Ruby “require'&书信电报;创业板>';`在没有捆绑机的情况下工作?,ruby,Ruby,我有一个脚本需要续集宝石: #!/usr/bin/env ruby puts "BEFORE:", $LOAD_PATH.sort require 'sequel' puts "AFTER:", $LOAD_PATH.sort puts self.method(:require).owner 我期望它在不使用bundler将gem的lib目录添加到加载路径的情况下失败,但它成功了 在输出中,您可以清楚地看到路径是由以下内容添加的: BEFORE: /usr/local/lib/ruby/2

我有一个脚本需要续集宝石:

#!/usr/bin/env ruby

puts "BEFORE:", $LOAD_PATH.sort
require 'sequel'
puts "AFTER:", $LOAD_PATH.sort

puts self.method(:require).owner
我期望它在不使用bundler将gem的lib目录添加到加载路径的情况下失败,但它成功了

在输出中,您可以清楚地看到路径是由以下内容添加的:

BEFORE:
/usr/local/lib/ruby/2.2.0
/usr/local/lib/ruby/2.2.0/x86_64-linux
/usr/local/lib/ruby/site_ruby
/usr/local/lib/ruby/site_ruby/2.2.0
/usr/local/lib/ruby/site_ruby/2.2.0/x86_64-linux
/usr/local/lib/ruby/vendor_ruby
/usr/local/lib/ruby/vendor_ruby/2.2.0
/usr/local/lib/ruby/vendor_ruby/2.2.0/x86_64-linux
AFTER:
/usr/local/bundle/gems/sequel-4.26.0/lib
/usr/local/lib/ruby/2.2.0
/usr/local/lib/ruby/2.2.0/x86_64-linux
/usr/local/lib/ruby/site_ruby
/usr/local/lib/ruby/site_ruby/2.2.0
/usr/local/lib/ruby/site_ruby/2.2.0/x86_64-linux
/usr/local/lib/ruby/vendor_ruby
/usr/local/lib/ruby/vendor_ruby/2.2.0
/usr/local/lib/ruby/vendor_ruby/2.2.0/x86_64-linux
Kernel
我甚至检查了方法所有者,查看
require
是否解析为Ruby内置的
Kernel::require
方法之外的其他方法,但它显然来自
Kernel

这是怎么回事


(使用Ruby 2.2.3。)

这是由RubyGems处理的,与Bundler无关。

只是在安装了两个不同版本的gem并在我的Gemfile中指定了旧版本的同时,使用require with/Under Bundler进行了一些测试。因此,总结一下我所学到的:(1)ruby将自动搜索已安装的gem并添加其加载路径,默认为每个gem的最新安装版本,而(2)bundler将确保指定版本的路径位于加载路径的第一位,以便您获得正确的路径。这是正确的吗?Bundler主要更改
GEM_路径
,这样RubyGems将查看Bundler管理的路径,类似于RVM等。更改
路径
,这样shell将查看RVM管理的路径。我想Bundler会更改加载路径。当然有些事情是这样的。更新:我对GEM_路径很好奇,所以我启动了IRB并评估了
ENV['GEM_PATH']
,得到了
nil
。然后我需要“bundler/setup”并再次求值,得到的是空字符串(
)。是的,RubyGems就是这样工作的。RubyGems更改
LOAD_路径
,以便
require
可以查看RubyGems管理的路径。它还覆盖了
require
,因此,如果找不到路径,它不会出错,而是首先检查某个Gem中是否存在该路径,并将该Gem添加到
加载路径中。