Learning Ruby stuck on ARGV.rb

I’m working through the book Apress Beginning Ruby.

I have text.txt file that we are using to tell me how many lines, words,
etc…are in the page copied from a book.

The next part in the book is telling me the following, by replacing my
text.txt to 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

It will be blank, but try this
ruby argv.rb test 123

*should result with test-123; However, I get:

NameError: undefined local variable or method ‘argv’ for main:Object

method in argv.rb at line 2
copy output
Program exited with code #1 after 0.07 seconds.

What am I not understanding? Why can’t I get this to work. The next part
is I replace my text.txt with ARGV[0] but, I’m not getting this part
correct.

Thanks,

ARGV is a special array, which consists of each space-separated token
(word) on the command line after your program.
In your example, ARGV[0] = ‘test’, ARGV[1] = ‘123’, etc.

I don’t have that particular book, but I hope I can give you a nudge.

The interpreter is quite correct; it understands that argv.rb is the
name of your program, but it doesn’t understand what ‘argv’ means
because the only object it knows about is ARGV.

SO, what you should do, is to change the program (Apress
usually is good about no typos, but this is an obvious one) to read:
puts ARGV.join(’-’)

… or, you could say argv = ARGV, then the join as they wrote it.

Now, here’s another suggestion. Before you join, say:

 count = ARGV.length
 puts "number of words: " + count.to_s
 stringofall = ARGV.join{'-')
 puts stringofall

… okay? Then, if you really get brave, try this:

 ruby argv.rb < test.txt

That means, ‘pipe the contents of test.txt into my program argv.rb’.
Unfortunately, this doesn’t work very well in Windows, which is why I
generally set friends up to learn Linux as well as Ruby.

ARGV is in all caps in the book. p. 95

Ruby is case sensitive. Be sure to pay attention to the case.