I hate  it when you are trying to learn something and what you are learning from is incomplete or wrong. This is the beginning of a ruby script I am writing which will (in the section shown) erase a file. ruby tells me that line 15 is wrong! It says:

    ex16.rb:15: undefined local variable or method `file' for main:Object (NameError)

I am guessing that what line 15 is doing is telling the program to make file 'target' smaller but it needs to know how small and the guy who writes Learn Code the Hard Way forgot to include that in his tutorial. Or else I'm wrong and in that case please  show me where I am wrong.

1 filename = ARGV.first #argument at command line is given a name
2 script = $0 #script is now titled  file's name
3
4 puts "We're going to erase the contents of #{filename}."
5 puts "If you don't want to do that hit CTRL-C."
6 puts "If you do want to do that then hit RETURN."
7
8 print "? "
9 STDIN.gets #it waits for input before going on
10
11 puts "Opening the file..."
12 target = File.open(filename, 'w') #tells it to open filename or to write it if non-existant
13                                                                                    ^^^^is this right?^^^^^^^^^^
14 puts "Truncating the file.  Goodbye!"
15 target.truncate(target.size)


--
:-)~MIKE~(-: