在我将RUBY_VERSION字符串拆分为句点并将这些位转换为整数之前等等,如果当前RUBY_VERSION的值大于X.X.X?,是否有更简单的方法可以检查Ruby程序?
the*_*Man 13
Ruby的Gem库可以进行版本号比较:
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
Run Code Online (Sandbox Code Playgroud)
有关详细信息,请参阅http://rubydoc.info/stdlib/rubygems/1.9.2/Gem/Version.