Every Day I'm Versioning (Gem versioning is important)

Posted on by Admin

The advent of Rails3 + Bundler makes gem versioning easy and mostly painless. Simply edit your Gemfile, bundle install, and you're done.

In other, non-Rails Ruby projects it's almost as simple: repeat the steps above and then include the require 'rubygems'; require 'bundler/setup' lines in your code.

But what about your standalone Ruby scripts (like this one)? Gem versioning is still very important so you aren't bitten by incompatible library versions when you have to reinstall your whole system six months from now. So what do you do?

Well as it turns out, Rubygems itself still has the ability to force gem versioning:

By using the gem method and passing in the proper version string (using, of course, ~> instead of >=) Rubygems ensures that when that gem is next required, it will conform to that versioning string. And if it's unable to find an installed gem that matches that string, it will raise a LoadError.

I can't stress enough how important it is to implement and respect proper semantic versioning in all aspects of development. It's a tiny amount of extra work up front to save you potentially hours of headaches further down the road. Just do it!

 
comments powered by Disqus