版本要求中的代字号大于(〜>)的含义? [英] Meaning of tilde-greater-than (~>) in version requirement?

查看:85
本文介绍了版本要求中的代字号大于(〜>)的含义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在gem规范中〜> 版本要求的含义是什么?

 
hanna-0.1.12取决于[haml(〜> 2.2.8)]


解决方案

RubyGems手册将此称为
悲观版本约束



假设您指定了一个n部分的版本号,例如(4部分)作为约束条件,将 1.3 (2部分)或
3.5.6.2 然后,为了完成约束,
a版本号必须同时满足以下两个条件:


  1. 第n个版本号的-1部分必须与约束
    的前n-1
    部分相同(例如 1.x 3.5.6.x 匹配,但 0.x 3.5.7.x 不)


  2. 版本号的最后一部分必须大于或等于最后一个
    部分约束
    (例如 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

  1. 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 or 3.5.6.x match, but 0.x or 3.5.7.x don't) and

  2. The last part of the version number must be greater than or equal to the last part of the constraint (e.g. 1.9999 and 3.5.6.2 match, but 1.2 or 3.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屋!

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