版本要求中的代字号大于(〜>)的含义? [英] Meaning of tilde-greater-than (~>) in version requirement?
问题描述
在gem规范中〜>
版本要求的含义是什么?
hanna-0.1.12取决于[haml(〜> 2.2.8)]
RubyGems手册将此称为
悲观版本约束。
假设您指定了一个n部分的版本号,例如(4部分)作为约束条件,将
1.3
(2部分)或 3.5.6.2
然后,为了完成约束,a版本号必须同时满足以下两个条件:
-
第n个版本号的-1部分必须与约束
的前n-1
部分相同(例如1.x
或3.5.6.x
匹配,但0.x
或3.5.7.x
不)和 -
版本号的最后一部分必须大于或等于最后一个
部分约束
(例如1.9999
和3.5.6.2
匹配,但1.2
或3.5.6.1
不)。
换句话说
〜> x_1.x_2.x_3。 … .x_n-2.x_n-1.x_n
匹配
x_1.x_2.x_3。 … .x_n-2.x_n-1.y,y = x_n
这个被称为悲观约束的原因,以及用于
的用例是,当你只是说>时, x.y.z
,你很乐观:你从现在开始假设
,直到所有的永恒,API永远不会改变。这
当然是一个非常大胆的假设。但是,大多数项目在允许
打破向后兼容性 a>,
以及他们在执行 时如何改变他们的版本号。您可以使用悲观的
约束对这些版本编号规则进行编码,因此您可以确保您的代码始终能够继续工作
(假定其他项目的作者实际上符合他自己的
规则,但不幸的事情并非总是如此)。
What's the meaning of ~>
version requirement in gem specs?
hanna-0.1.12 depends on [haml (~> 2.2.8)]
The RubyGems manual calls this a pessimistic version constraint.
Assume you have specified an n-part version number, e.g. 1.3
(2-part) or
3.5.6.2
(4-part) as the constraint. Then, in order to fulfill the constraint,
a version number must satisfy both of the following conditions
The first n-1 parts of the version number must be identical to the first n-1 parts of the constraint (e.g.
1.x
or3.5.6.x
match, but0.x
or3.5.7.x
don't) andThe last part of the version number must be greater than or equal to the last part of the constraint (e.g.
1.9999
and3.5.6.2
match, but1.2
or3.5.6.1
don't).
In other words
~> x_1.x_2.x_3. … .x_n-2.x_n-1.x_n
matches
x_1.x_2.x_3. … .x_n-2.x_n-1.y, y = x_n
The reason this is called a "pessimistic" constraint, and also the use case for
it, is that when you just say > x.y.z
, you are being optimistic: you assume
that from here on out, until all eternity, the API will never ever change. This
is of course a pretty bold assumption. However, most projects have rules about
when they are allowed to
break backwards compatibility,
and how they have to change their version number when they do break backwards
compatibility. You can encode those version numbering rules using a pessimistic
constraint, and thus you can be sure that your code will always continue to work
(assuming that the author of the other project actually adheres to his own
rules, which unfortunately isn't always the case).
这篇关于版本要求中的代字号大于(〜>)的含义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!