简体   繁体   English

Bundler - 无法加载2个不同版本的完全相同的gem?

[英]Bundler - cannot load 2 different versions of the exact same gem?

I've watched this presentation on how Bundler works and one of the reasons Bundler was invented was to solve 'activation errors', for eg: 我看过Bundler如何工作的这个演示文稿,Bundler被发明的原因之一是解决“激活错误”,例如:

LoadError: can't activate rack (~> 1.0.0, runtime) for ['actonpack-2.3.5'], already activated rack-1.1.0 for ['thin-1.2.7']

Does this basically means that you cannot run 2 different versions of the exact same gem at a same time, in a single Ruby process? 这基本上意味着你不能在一个Ruby进程中同时运行两个不同版本的完全相同的gem吗?

You cannot have two different versions of the same gem loaded the same program, because they could conflict and override each other's methods. 您不能将同一个gem的两个不同版本加载到同一个程序中,因为它们可能会冲突并覆盖彼此的方法。 For example, suppose you have a gem which contains the following: 例如,假设您有一个包含以下内容的gem:

# In gem version 1.0
class AneMaria
  def self.name
    "Ane"
  end
end

######

# In gem version 2.0
class AneMaria
  def self.name
    "Maria"
  end
end

And then in your code, if you call AneMaria.name , what should it return?? 然后在你的代码中,如果你调用AneMaria.name ,它应该返回什么?

One of the reasons tools like bundler were created was to prevent this from happening accidentally -- so no, you cannot specify 2 different versions of a gem to load simultaneously. 创建像bundler这样的工具的原因之一是为了防止这种情况意外发生 - 所以不,你不能指定两个不同版本的gem同时加载。 (Also, I don't think you'll ever want to do that!) (另外,我认为你不会想那样做!)

See also this post , which explains things a little more. 另见这篇文章 ,它解释了一些事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM