Let’s say the following releases of a gem exist:
Version 2.1.0 — Baseline Version 2.2.0 — Introduced some new (backward compatible) features. Version 2.2.1 — Removed some bugs Version 2.2.2 — Streamlined your code Version 2.3.0 — More new features (but still backwards compatible). Version 3.0.0 — Reworked the interface. Code written to version 2.x might not work.Someone who wants to use your gem has determined that
# gemspec spec.add_runtime_dependency 'library', '>= 2.2.0'or
# bundler gem 'library', '>= 2.2.0'This is an optimistic version constraint.
It’s saying that all
changes from 2.x
on will work with my software,
but for version
3.0.0
this may not be true.
This explicitly excludes the version that might break your code.
# gemspec spec.add_runtime_dependency 'library', ['>= 2.2.0', '< 3.0']or
# bundler gem 'library', '>= 2.2.0', '< 3.0'
# gemspec spec.add_runtime_dependency 'library', '~> 2.2'
# bundler gem 'library', '~> 2.2'Notice that we dropped the
PATCH
level of the version number.
~> 2.2.0
, that would have been equivalent to
['>= 2.2.0', '< 2.3.0']
.
# gemspec spec.add_runtime_dependency 'library', '~> 2.2', '>= 2.2.1'
# bundler gem 'library', '~> 2.2', '>= 2.2.1'
~>
instead of >=
if at all possible.
Casiano Rodriguez León 2015-01-07