Extra credit for ex16. Must remember the 1.8 incompatibility thing.
This commit is contained in:
parent
428e83efd1
commit
1b00a0f514
30
ex16-ec.rb
Normal file
30
ex16-ec.rb
Normal file
@ -0,0 +1,30 @@
|
||||
filename = ARGV.first
|
||||
script = $0
|
||||
|
||||
puts <<EOF
|
||||
We're going to erase #{filename}.
|
||||
If you don't want that, hit CTRL-C (^C).
|
||||
If you do want that, hit RETURN.
|
||||
EOF
|
||||
|
||||
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}\n#{line2}\n#{line3}\n")
|
||||
|
||||
puts "And finally, we close it."
|
||||
target.close
|
Loading…
Reference in New Issue
Block a user