Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does a Gem provide ~> AND => in RubyGems?

The gem for bcrypt at https://rubygems.org/gems/bcrypt/versions/3.1.11

shows this usage

gem 'bcrypt', '~> 3.1', '>= 3.1.11'

Why have the two versions of the pessimistic operator ?

We normally use just one version for other gems

like image 957
Michael Durrant Avatar asked Aug 29 '16 23:08

Michael Durrant


2 Answers

>= 3.1.11 is an “optimistic” version constraint. It’s saying that all changes from 3.1.11 on will work, but for version 4.0.0 this will not be true.

~> 3.1 is “pessimistic”. This explicitly excludes the version that might break your code. It is basically saying >= 3.1 and < 4.0. But if you had ~> 3.1.1, it will be equal to >= 3.1.1 but less than 3.2

If you want to allow use of newer backwards-compatible versions but need a specific bug fix you can use a compound requirement like '~> 3.1', '>= 3.1.11' This is detailed at http://guides.rubygems.org/patterns/#pessimistic-version-constraint If you want to allow use of newer backwards-compatible versions but need a specific bug fix you can use a compound requirement such as... '~> 2.2', '>= 2.2.1'

like image 132
davidhu Avatar answered Sep 22 '22 22:09

davidhu


'~> 3.1' means the required version can be 3.1.x or 3.2.x or 3.3.x or ..., but never to reach 4.0.

The meaning of '>= 3.1.11' is quite clear.

So put them together, it means the version can be 3.x.y where x >= 2 or x = 1 and y >= 11.

Maybe this notation is more clear:

gem 'bcrypt', '>= 3.1.11', '< 4'
like image 38
Aetherus Avatar answered Sep 23 '22 22:09

Aetherus