2017-01-12 155 views
0

我在ruby程序中寻找一种方式来确定运行我的程序的Ruby版本以及Standard Libary的版本?以编程方式获取当前版本的ruby标准库

+6

的'RUBY_VERSION'不变? –

+0

标准库怎么样? – grbonk

+1

标准库没有特定的版本。它总是假定与MRI Ruby版本相同,但在JRuby的情况下它可能会有所不同。 – tadman

回答

0

Ruby的版本存储在RUBY_VERSION全局常量中。

puts RUBY_VERSION 

您可以比较使用的RubyGems提供的类版本:

min_ruby_version = Gem::Requirement.new(">=2.2.0") 
current_ruby_version = Gem::Version.new(RUBY_VERSION) 

# check if ruby conforms to version req using =~ operator 
if min_ruby_version =~ current_ruby_version 
    do_this 
else 
    do_that 
end 
相关问题