How to compare semantic version strings in Ruby

There are several ways to compare semver strings in Ruby. One approach is turn each version string in to an array of integers and then use the array comparison operator <=>:

However this approach reports that “0.3.0” is greater than “0.3”:

The approach that has worked better for me is to use the Gem::Version class:

(this post was originally published in my tumblr: