Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Have a ruby script output what version of ruby is running it

Tags:

ruby

How do I have my ruby script output what version of ruby is running it?

like image 571
David Oneill Avatar asked Dec 15 '10 20:12

David Oneill


People also ask

What is the output of Ruby code?

In this part of the Ruby tutorial, we talk about input & output operations in Ruby. Input is any data that is read by the program, either from a keyboard, file or other programs. Output is data that is produced by the program. The output may go to the screen, to a file or to another program.

How do I print output in Ruby?

We use the puts, print and "p" methods in Ruby to display text (or other data types). With stdin, we handle input from the console. Operators like << are helpful. And often a loop is used to create an interactive console program with a prompt.

What is Ruby version file?

Many Ruby (or Rails) projects will include a simple .ruby-version file, which simply specifies a version number, for example: 2.4.2. Popular tools to help you manage your Ruby version are: Ruby Version Manager (RVM)


1 Answers

The RUBY_VERSION constant contains the version number of the ruby interpreter and RUBY_PATCHLEVEL contains the patchlevel, so this:

puts RUBY_VERSION 

outputs e.g. 2.2.3, while this:

puts RUBY_PATCHLEVEL 

outputs e.g. 173. Together it can be used like this:

ruby -e 'print "ruby #{ RUBY_VERSION }p#{ RUBY_PATCHLEVEL }"' 

to output e.g. ruby 2.2.3p173

like image 66
wdebeaum Avatar answered Oct 13 '22 11:10

wdebeaum