Define Ruby Version from Rails

Is there a way to determine which version of Ruby works from Rails (either on the Internet or through script/console )? I have installed Ruby 1.8.6, but I also installed Ruby Enterprise Edition 1.8.7-20090928 and want to make sure that it uses the correct installation.

+71
ruby ruby-on-rails ruby-enterprise-edition
Oct 19 '09 at 16:34
source share
4 answers

Use top level constant

 RUBY_VERSION 

other useful top level constants:

 RUBY_PATCHLEVEL RUBY_PLATFORM RUBY_RELEASE_DATE 

here's the irb session:

 irb(main):001:0> RUBY_VERSION => "1.8.7" 
+137
Oct 19 '09 at 16:41
source share

Try the RUBY_VERSION constant. I use this extensively to determine if I am running under 1.8 or JRuby.

Alternatively, if you are not in production mode, you can perform a quick check by clicking the URL "/ rails / info / properties"

+12
Oct 19 '09 at 16:40
source share

Besides the RUBY_VERSION constant and friends, you can also check Config :: CONFIG. This hash contains not only version numbers, but also a ton of other useful information about the runtime, for example, the path to the binary, hostname, ...

+9
Oct 21 '09 at 2:08
source share

Use RUBY_VERSION as mentioned by others.

Then you can use Gem::Version to compare version strings:

 require 'rubygems' # Only needed for ruby pre-1.9.0 but it 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 
+4
Mar 02 '15 at 10:25
source share



All Articles