How do I have my ruby script output what version of ruby is running it?
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.
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.
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)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With