〜>之间的区别是什么? > =在Gemfile中指定rubygem时? [英] What is the difference between ~> and >= when specifying rubygem in Gemfile?

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

问题描述

  gemcucumber,〜> 0.8在Gemfile中我经常看到以下符号(〜>)。 .5
gemrspec,〜> 1.3.0

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

解决方案

这是悲观版本约束。 RubyGems将增加所提供版本中的最后一位数字,并使用它,直到达到最大版本。因此〜> 0.8.5 在语义上相当于:

gemcucumber ,> = 0.8.5,<0.9.0



想想这件事的简单方法是,可以用最后一位增加到某个任意值的数字来确定,但是在字符串前面的数字不能大于你提供的值。因此,对于〜> 0.8.5 ,任何值对于第三位数字(5)都是可接受的,只要它大于或等于5,但前导0.8必须例如,如果您认为0.9版本将实施一些突破性更改,但您知道整个0.8版本,则可以使用0.8。 但是,只要使用> = 0.8.5就可以表明这一点。任何版本晚于(或等于)0.8.5是可以接受的。没有上限。


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?

解决方案

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 "cucumber", ">=0.8.5", "<0.9.0"

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".

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.

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中指定rubygem时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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