为什么要求选择最新版本gem?
Why does require choose the latest version of a gem?
如果我加载 gem,假设 activerecord
,在 IRB require
中选择最新版本的 activerecord
。从程序上讲,是什么影响了选择最新 gem 版本的决定? require
是这样做的,还是加载的 IRB 中有什么东西强制要求选择最新版本?
这是我的 activerecord gems 由 bundler 安装:
➜ ~ ls -al /Users/robskrob/.rvm/gems/ruby-2.4.1/gems/activere
activerecord-4.2.10/ activerecord-5.0.0.1/ activerecord-5.1.2/ activerecord-5.1.3/ activerecord-5.1.4/ activerecord-5.1.5/ activerecord-5.1.6/ activeresource-5.0.0/
这是一个 IRB 会话示例:
➜ ~ irb
2.4.1 :001 > require 'active_record'
=> true
2.4.1 :002 > Gem.loaded_specs['activerecord'].version
=> #<Gem::Version "5.1.6">
2.4.1 :003 >
If I load a gem, let's say activerecord
, in IRB require
chooses the latest version of activerecord
.
实际上,它选择了最新版本that doesn't conflict with any already activated gem。
Programmatically, what is influencing this decision to choose the latest gem version? Is require
doing this, or is there something in the loaded IRB that forces requires to choose the latest version?
这是require
的工作。更具体地说,它是 the monkey-patched require
from the RubyGems library, not the original require
from the Ruby core library.
的工作
这只是简单的关注点分离:IRb 是一个 REPL,而不是包管理系统,它不应该知道任何关于包的信息。
如果我加载 gem,假设 activerecord
,在 IRB require
中选择最新版本的 activerecord
。从程序上讲,是什么影响了选择最新 gem 版本的决定? require
是这样做的,还是加载的 IRB 中有什么东西强制要求选择最新版本?
这是我的 activerecord gems 由 bundler 安装:
➜ ~ ls -al /Users/robskrob/.rvm/gems/ruby-2.4.1/gems/activere
activerecord-4.2.10/ activerecord-5.0.0.1/ activerecord-5.1.2/ activerecord-5.1.3/ activerecord-5.1.4/ activerecord-5.1.5/ activerecord-5.1.6/ activeresource-5.0.0/
这是一个 IRB 会话示例:
➜ ~ irb
2.4.1 :001 > require 'active_record'
=> true
2.4.1 :002 > Gem.loaded_specs['activerecord'].version
=> #<Gem::Version "5.1.6">
2.4.1 :003 >
If I load a gem, let's say
activerecord
, in IRBrequire
chooses the latest version ofactiverecord
.
实际上,它选择了最新版本that doesn't conflict with any already activated gem。
Programmatically, what is influencing this decision to choose the latest gem version? Is
require
doing this, or is there something in the loaded IRB that forces requires to choose the latest version?
这是require
的工作。更具体地说,它是 the monkey-patched require
from the RubyGems library, not the original require
from the Ruby core library.
这只是简单的关注点分离:IRb 是一个 REPL,而不是包管理系统,它不应该知道任何关于包的信息。