What is ARGV
and how do I use it?
Asked
Active
Viewed 293 times
-4
-
also what is the difference between ARGV and ARGV.first? – Cluesade Jan 21 '15 at 23:24
-
2You are trying to `Learn ruby the hard way` and you are taking the easy way out just asking people how to do it. This is not the place. – djv Jan 21 '15 at 23:29
1 Answers
1
ARGV is basically an array that contains the elements passed to your script. You may find this StackOverflow question useful.
To test it, try creating .rb (let's say it's "test.rb") file in specific folder and put the following code there:
puts ARGV.inspect
Now, try opening a command line window/terminal and point it to the folder where "test.rb" is. Once you're there, type this in your terminal:
ruby test.rb a 1 b
You should get ["a", "1", "b"]
which is the content of ARGV
.