dan dan - 1 year ago 80
Ruby Question

How to check if the RUBY_VERSION is greater than a certain version?

Before I split the

string on a period and convert the bits into integers and so on, is there a simpler way to check from a Ruby program if the current
is greater than

Answer Source

Ruby's Gem library can do version number comparisons:

require 'rubygems' # not needed with Ruby 1.9+

ver1 = Gem::Version.new('1.8.7') # => #<Gem::Version "1.8.7">
ver2 = Gem::Version.new('1.9.2') # => #<Gem::Version "1.9.2">
ver1 <=> ver2 # => -1

See http://rubydoc.info/stdlib/rubygems/1.9.2/Gem/Version for more info.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download