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

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

问题描述

gem 规范中~> 版本要求是什么意思?

<前>hanna-0.1.12 取决于 [haml (~> 2.2.8)]

解决方案

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

假设您指定了一个 n 部分版本号,例如1.3(2 部分)或3.5.6.2 (4-part) 作为约束.然后,为了满足约束,版本号必须满足以下两个条件

  1. 版本号的前 n-1 部分必须与前 n-1 部分相同约束的部分(例如 1.x3.5.6.x 匹配,但 0.x3.5.7.x> 不要)

  2. 版本号的最后一部分必须大于或等于最后一部分约束的一部分(例如 1.99993.5.6.2 匹配,但 1.23.5.6.1 不匹配).

换句话说

<前>~> x1.x2.x3.….xn-2.xn-1.xn

匹配

<前>x1.x2.x3.….xn-2.xn-1.y, y >= xn

这被称为悲观"约束的原因,也是用例它,就是当你只说 >x.y.z,你很乐观:你假设从现在开始,直到永远,API 永远不会改变.这个当然,这是一个相当大胆的假设.但是,大多数项目都有关于当他们被允许打破向后兼容性,以及当他们确实向后中断时如何更改他们的版本号兼容性.您可以使用悲观方法对这些版本编号规则进行编码约束,因此您可以确保您的代码将始终继续工作(假设其他项目的作者实际上坚持自己的规则,不幸的是,情况并非总是如此).

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

~> x1.x2.x3. … .xn-2.xn-1.xn

matches

x1.x2.x3. … .xn-2.xn-1.y, y >= xn

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天全站免登陆