有什么区别~>和 >= 在 Gemfile 中指定 ruby​​gem 时? [英] What is the difference between ~> and >= when specifying rubygem in Gemfile?

查看:14
本文介绍了有什么区别~>和 >= 在 Gemfile 中指定 ruby​​gem 时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常在 Gemfile 中看到以下符号(~>).

I often see the following notation(~>) in Gemfile.

gem "cucumber", "~>0.8.5"
gem "rspec", "~>1.3.0"

我知道符号 (>=) 只是大于或等于,但是 (~>) 符号是什么意思?它们是否相同或有任何显着差异?

I know the sign (>=) is just greater or equal to, but what does the (~>) notation mean? Are they both same or has any significant difference?

推荐答案

这是一个悲观版本约束.RubyGems 将增加提供的版本中的最后一位数字并使用它,直到达到最大版本.所以 ~>0.8.5 在语义上等价于:

That's a pessimistic version constraint. RubyGems will increment the last digit in the version provided and use that until it reaches a maximum version. So ~>0.8.5 is semantically equivalent to:

gem "黄瓜", ">=0.8.5", "<0.9.0"

考虑它的简单方法是,您可以将最后一个数字增加到某个任意值,但字符串中它前面的数字不能大于您提供的值.因此,对于 ~>0.8.5,第三个数字(5)的任何值都可以接受,只要它大于或等于 5,但前导 0.8 必须是0.8".

The easy way to think about it is that you're okay with the last digit incrementing to some arbitrary value, but the ones preceding it in the string cannot be greater than what you provided. Thus for ~>0.8.5, any value is acceptable for the third digit (the 5) provided that it is greater than or equal to 5, but the leading 0.8 must be "0.8".

您可能会这样做,例如,如果您认为 0.9 版本将实施一些重大更改,但您知道整个 0.8.x 版本系列只是错误修复.

You might do this, for example, if you think that the 0.9 version is going to implement some breaking changes, but you know the entire 0.8.x release series is just bugfixes.

但是,简单地使用 ">=0.8.5" 将表明 任何 版本晚于(或等于)0.8.5 是可以接受的.没有上限.

However, simply using ">=0.8.5" would indicate that any version later than (or equal to) 0.8.5 is acceptable. There is no upper bound.

这篇关于有什么区别~&gt;和 &gt;= 在 Gemfile 中指定 ruby​​gem 时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆