在 ruby .gemspec 文件中,如何指定依赖项的多个版本?
问题描述:
我正在尝试修改当前依赖于活动资源的 gem,定义为:
I'm trying to modify a gem which currently has a dependency on activeresource defined as:
s.add_dependency "activeresource", "~> 3.0"
为了让 gem 与 Rails 4 一起工作,我需要扩展依赖项以与版本 3 或 4 的 activeresource 一起使用.我不想简单地添加以下内容,因为它可能会导致以后出现问题:
In order to get the gem working with Rails 4, I need to extend the dependency to work with either version 3 or 4 of activeresource. I don't want to simply add the following as it could cause problems later:
s.add_dependency "activeresource", ">= 3.0"
有没有办法指定可接受版本的列表?~> 3.0 还是 ~> 4.0?
Is there a way to specify a list of acceptable versions? ~> 3.0 or ~> 4.0?
答
根据文档,如果需要要拥有 3 到 4 之间的所有版本,您可以这样做:
Accordly to the documentation, if you want to have all version between 3 and 4, you can do this :
s.add_dependency "activeresource", ">= 3.0", "< 5.0"
接受的说明符是:>=, ~>, <=, >, <
.