Determine ruby version from within Rails

后端 未结 4 2023
时光取名叫无心
时光取名叫无心 2020-12-07 19:46

Is there a way to determine what version of Ruby is running from within Rails (either on the web or through script/console)? I have Ruby 1.8.6 installed but I\'

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-07 20:17

    Use RUBY_VERSION as mentioned by others.

    You can then use Gem::Version to do version string comparison:

    require 'rubygems' # Only needed for ruby pre-1.9.0 but it's safe for later versions (evaluates to false).
    if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('1.9.0')
        extend DL::Importable                                    
    else                                                         
        extend DL::Importer                                      
    end                                                          
    

提交回复
热议问题