In Rails Gemfile, what are the differences between these :
gem "gemname", "~> 4.0.1"
and
gem "gemname", "4.0.1"
and
gem "gemname"
Also what should be used where and benefit of following that way?
There are several ways to specify gem versions: Use a specific version: gem "name-of-gem", "1.0" . You can find specific versions on Rubygems.org (provided that's the source you”re using) by searching for your gem and looking at the “Versions” listed. Use a version operator: gem "name-of-gem", ">1.0" .
In other words: ~> means it will only allow that specific version, and newer sub-versions in the last decimal.
The Gemfile is where you specify which gems you want to use, and lets you specify which versions. The Gemfile. lock file is where Bundler records the exact versions that were installed. This way, when the same library/project is loaded on another machine, running bundle install will look at the Gemfile.
Gemspec is basically the Readme for gems. It tells you about the author, version, summary, description, internal dependencies, execution and everything about the Gem.
The first will tell bundler to load any gem that varies with the last (patch) number. So 4.0.x where x is 1 or greater.
The second will only load 4.0.1.
The third will get the highest value that works (depending on what the needs of the rest of your gems in your Gemfile) or will get whatever is specified in your Gemfile.lock, if you have one.
I missed your second question. Frankly, it depends. For the most part, I go with the first option, because it lets me pick up bug fixes without worrying about how it impacts my other gems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With