Here is the text I am typing in - I have a text.txt as the text file which shows up when I run the program but then I get and error (copied at the bottom of this post). I have compared my test with the book example but cannot see a difference - anyone any ideas?
filename = ARGV.first
puts “We’re going to erase #{filename}”
puts “If your don’t want to do that, hit CTRL-C (^C).”
puts “If you do want to do that, hit RETURN.”
$stdin.gets
puts “Opening the file…”
target = open(filename, ‘W’)
puts “Truncating the file. Goodbye)”
target.truncate(0)
puts “Now I’m going to ask you for three lines.”
print "line 1: "
line1 = $stdin.gets.chomp
print "line 2: "
line2 = $stdin.gets.chomp
print "line 3: "
line3 = $stdin.gets.chomp
puts “I’m going to write these to the file”
target.write(line1)
target.write("\n")
target.write(line2)
target.write("\n")
target.write(line3)
target.write("\n")
puts “And finally we close it.”
target.close
Error
Traceback (most recent call last):
1: from ex16.rb:7:in <main>' ex16.rb:7:in
gets’: Interrupt