Using Twiddle Wakka in your Gemfile
You might have come across something like this in your Gemfile: gem 'rails', '~> 5.2'
. The tilde (~) that appears is the Twiddle Wakka, a simplified syntax to make writing easier.
Assuming you already use Semantic Versioning to version your apps and gems, let's consider how you restrict calls to these versions when managing them in the Gemfile. There are two types of version constraints: optimistic and pessimistic.
Imagine a gem called Lib with the following versions:
Lib 1.8.0
Lib 2.1.0
Lib 2.2.0
Lib 2.2.1
Lib 2.3.5
Lib 3.0.0
I would like to restrict versions below 2.1.0 and allow all versions from 2.1.0 onwards to be installed. In this case, I would be optimistic.
gem 'lib', '>= 2.1.0'
It's possible that version 3.0.0 may not be compatible with my application, so I need to restrict pessimistically, specifying the bounds within which the bundle can install.
gem 'lib', '>= 2.1.0', '< 3.0.0'
Now, we ensure that the bundle can install all versions greater than or equal to 2.1.0 and less than 3.0.0.
The Twiddle Wakka is a way to write less, see:
gem 'lib', '~>= 2.2'
This is equivalent to ['>= 2.2.0', '< 2.3.0']
. Or, if I want to include all versions with a major of 2, I can do it like this:
gem 'lib', '~>= 2'
This is equivalent to ['>= 2.0.0', '< 3.0.0']
.
Reference: https://guides.rubygems.org/patterns/