6

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

Ryan Gates
  • 4,501
  • 6
  • 50
  • 90
Michael Durrant
  • 93,410
  • 97
  • 333
  • 497

2 Answers2

3

'~> 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'
Aetherus
  • 8,720
  • 1
  • 22
  • 36
3

>= 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'

Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
davidhu
  • 9,523
  • 6
  • 32
  • 53