Skip to content

Instantly share code, notes, and snippets.

@andersondias
Last active December 28, 2018 14:00
Show Gist options
  • Save andersondias/5998cb47547f2dd7d4d0 to your computer and use it in GitHub Desktop.
Save andersondias/5998cb47547f2dd7d4d0 to your computer and use it in GitHub Desktop.
How to compare version strings in Ruby
# Compares if a version is greater than other.
Gem::Version.new('2.1.15') > Gem::Version.new('1.14.1')
# => true
# It supports any number of minor versions
Gem::Version.new('2.0.0.1') < Gem::Version.new('2.0.1')
# => true
# And it deals with empty strings and nil values
Gem::Version.new('') < Gem::Version.new('2.0.1')
# => true
Gem::Version.new(nil) < Gem::Version.new('2.0.1')
# => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment