Last active
December 28, 2018 14:00
-
-
Save andersondias/5998cb47547f2dd7d4d0 to your computer and use it in GitHub Desktop.
How to compare version strings in Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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