Ruby - Introduction Commandline Argument

Introduction

Ruby places any parameters that are appended to the command line when you launch your Ruby program into a special array called ARGV.

To test it out, create a new script called argv.rb and use this code:

puts ARGV.join('-') 

From the command prompt, run the script like so:

ruby argv.rb 

The result will be blank, but then try to run it like so:

ruby argv.rb test 123 

Output:

test-123 

Here, the parameters are taken from ARGV, joined together with a hyphen, and displayed on the screen.