box-o-sand/lrthw-remnants/ex16.rb
Dan Buch 01e5a4e45f Add 'lrthw-remnants/' from commit '2b0a814a1795c60baf29b95462921b0ec8c7d861'
git-subtree-dir: lrthw-remnants
git-subtree-mainline: f2380eef05
git-subtree-split: 2b0a814a17
2013-01-09 23:47:30 -05:00

34 lines
715 B
Ruby

filename = ARGV.first
script = $0
puts "We're going to erase #{filename}."
puts "If you don't want that, hit CTRL-C (^C)."
puts "If you do want that, hit 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 "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()