-4

What is ARGV and how do I use it?

sawa
  • 165,429
  • 45
  • 277
  • 381
Cluesade
  • 13
  • 3
  • also what is the difference between ARGV and ARGV.first? – Cluesade Jan 21 '15 at 23:24
  • 2
    You 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 Answers1

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.

Community
  • 1
  • 1
daremkd
  • 8,244
  • 6
  • 40
  • 66