What is the difference between -v and --version in Ruby
--version are command line switches that interact with the Ruby interpreter by instructing the output of Ruby version information. Although both can be used in the same way there is a small difference between them.
--version command line switch, we can instruct the Ruby interpreter to output the current Ruby version information only. In order to do that, we simply run in the command line
ruby --version and we can the following output depending on the version of ruby you have:
$ ruby --version ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
-v switch can be used similarly. You can run it by executing
ruby -v and it will produce the exact same output as
ruby --version does. However,
ruby -v can be used also in conjunction with the program file to be executed. Therefore, if we have a hello_world.rb program file with just a
puts “Hello world” and execute it by running
ruby -v hello_word.rb we get the following:
$ ruby -v hello_word.rb ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux] Hello world
You might think that
-v stands for version only, but you are mistaken. The
-v stands for both verbose mode and version. It shows the Ruby version information only or executes the program in verbose mode (= showing before program outputs the Ruby version). The program execution in verbose mode can be quite handy when experimenting with code across different versions of Ruby, where changes between versions can affect big parts of your existing codebase.