I got the above error when trying to reduce 5 lines to 1, using target.write:
target.write("%s \n %s \n %s \n") % [line1, line2, line3]
# target.write("\n")
# target.write(line2)
# target.write("\n")
# target.write(line3)
# target.write("\n")
The commented section ran(when the 1st line was target.write(line1), but this does not.
Why isn’t the very first line the same as writing the commented out six lines? here is the whole script:
filename = ARGV.first
script = $0
puts "We're going to erase #{filename}."
puts "If you don't want that hit control C"
puts "If you do want that hit execute or return"
print "? "
STDIN.gets
puts "Opening the file..."
target = File.open(filename, 'w')
puts "Truncating the file. Goodbye!"
target.truncate(target.size)
puts "Now I'm going to ask you for three lines."
print "line1: "; line1 = STDIN.gets.chomp()
print "line2: "; line2 = STDIN.gets.chomp()
print "line3: "; line3 = STDIN.gets.chomp()
puts "I'm going to write these to the file."
target.write("%s \n %s \n %s \n") % [line1, line2, line3]
# target.write("\n")
# target.write(line2)
# target.write("\n")
# target.write(line3)
# target.write("\n")
puts "And finally we close it"
target.close()
The closing paren on the
target.writeline is in the wrong place. Try