This question already has answers here:
Meaning of tilde-greater-than (~>) in version requirement?
(4 answers)
Closed 8 years ago.
What does ~> mean in the context of Ruby gem depenedencies?
For example, when opening a legacy project in the RubyMine IDE, I get this
message
Gems required for project are not attached:
arel (~> 2.0.2),
rspec-expectation (~> 2.5.0)...
I've seen this tilde-greater-than notation elsewhere in the Ruby world (it's not
specific to RubyMine). Does this operator have a name other than the
awkward-sounding tilde-greater-than?
It means "equal to or greater than in the last digit", so e.g. ~> 2.3 means
"equal to 2.3 or greater than 2.3, but less than 3.0", while ~> 2.3.0 would
mean "equal to 2.3.0 or greater than 2.3.0, but less than 2.4.0".
You can pronounce it as "approximately greater than".
ยง Pessimistic version constraint
it means bring any lower version equal or greater than, but not a major version.
So for example arel (~> 2.0.2), will use (if availble) versions
2.0.2
2.0.3
2.0.? (as long as ? is >= 2)
but it won't use 2.1.?
According to the internet
If a RubyGem dependency uses the syntax "~> 1.4.37", that means "a version greater than or equal to 1.4.37, but not 1.5 or higher." 1
In other words, for you
arel can be 2.1 > version >= 2.0.2 and
rspec-expectation can be 2.6 > version >= 2.5.0.
What this means is that you are expecting a gem that is version 2.0.2 or higher, but not 2.1 in the case of arel (~> 2.0.2) This is done since people are not supposed to release breaking syntax changes in minor revisions. So arel 2.0.3 would be expected to have bug/stability fixes over 2.0.2
Related
I currently have a dependency of the following
i18n (~> 0.6, >= 0.6.4)
I've been having a read through of the Ruby Gems - Declaring Dependency Guide
And I've found out that the '~> 0.6' part means anything between 0.6 and 1.0 - correct me if that's wrong.
But I'm still confused, what does this actually mean with a second comma separated value?
A colleague believes it means
>= 0.6.4, <= 0.7
But I'm not so sure.
short answer: as pointed by Holger in the comments, ~> 0.6, >= 0.6.4 means >= 0.6.4 and < 1.0.
The ~> operator is called pessimistic operator (or twiddle-wakka), and its objective is to guard the gems from potential bugs/failures in future releases.
When you're building a gem, you must create a special Specification Class and put it in a .gemspec file or in a Rakefile. This class contains the information for the gem, like its name, version, license and the dependencies.
And is a good practice specify the dependencies following a pessimistic version constraint. Therefore, notations like ~> 0.6, >= 0.6.4 are very common.
You can find more information here.
I'm just trying to use the simple career_builder gem and just get it imported by running the simple script:
require 'career_builder'
puts 'Hello world!'
and yet get the following error: /Library/Ruby/Site/2.0.0/rubygems/dependency.rb:315:in 'to_specs': Could not find 'activesupport' (~> 2.3.5) - did find: [activesupport-4.2.1,activesupport-3.1.12,activesupport-3.0.3] (Gem::LoadError)
I installed the gem with gem install career_builder and ran bundle install and even updated activesupport to the most recent version, but for some reason, the program can't find the newer version of activesupport. Does the gem require version 2.3.5?
http://guides.rubygems.org/patterns/
The ~>or 'twiddle-waka' is a ruby gems shortcut to specify the earliest version of the gem you can use without letting you go up to the next major release.
Your gem is being a bit unorthodox and also specifying a patch level.
So the gem_specification you're working with (activesupport' (~> 2.3.5)) really means minimum version of 2.3.5 maximum of the last patch released before 2.4.0.
The activesupport versions you have installed are all for subsequent major releases and won't work. Install something between 2.3.5 and 2.4.0 and you should be good to go.
Yes. It does require Active Support version >= 2.3.5 and < 2.4.0. All of your Active Support versions are > 2.4.0.
~> is called the spermy operator. See Meaning of tilde-greater-than (~>) in version requirement?
The gem has not been updated in 4 years, so it uses Rails 2.
FWIW, I don't think you'll have much luck getting it to work, so you may want to find a similar gem that works with Rails 4 and has been updated within the last few months.
Currently I have a Gemspec that requires a specific version of Rails 3.x with Rails > 3.1:
Gem::Specification.new do |s|
# (...)
s.add_dependency "railties", "~> 3.1"
# (...)
end
I am looking to update this statement to require ~> 3.1 OR ~> 4.0.0. I had tried already:
~> 3.1, ~> 4.0.0
~> 3.1 OR ~> 4.0.0
~> 3.1 || ~> 4.0.0
~> 3.1 ~> 4.0.0
None have worked. Is that possible with the current RubyGems version?
For now I am using > 3.1, but the real question is if that's possible.
Since you are using ~>, it seems as if you are willing to use any version of the gem that is after 3.1, that is, any 3.x OR any 4.0.x, but not a 4.x where x is greater than 1.
If that is your intention, then according to the rubygems guide, you'll want to use a pattern like:
spec.add_dependency 'library', ['>= 3.1', '< 4.1']
I think it might be the addition of brackets that you need.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Meaning of tilde-greater-than (~>) in version requirement?
I see something like this a lot in gemspecs:
s.add_dependency 'some_gem', '~> 1.5.0'
What does ~> mean?
From gembundler
The specifier ~> has a special meaning, best shown by example.
~> 2.0.3 is identical to >= 2.0.3 and < 2.1.
~> 2.1 is identical to >= 2.1 and < 3.0.
~> 2.2.beta will match prerelease versions like 2.2.beta.12.
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Meaning of ~> in version requirement
I often stumble upon the ~> operator.
eg.
gem 'httparty', '~> 0.5.2'
What does it mean?
It's called a pessimistic version constraint. It matches a gem version by dropping the last digit and comparing equality. For example, ~> 0.5.2 would match version 0.5.2 or 0.5.3, but not 0.5 or 0.6. It's basically equivalent to a constraint of >= 0.5.2, < 0.6.
It means that any version >= 0.5.2 and < 0.6.0
Yehuda Katz recently wrote about this - http://yehudakatz.com/2010/08/21/using-considered-harmful-or-whats-wrong-with/