From a295260e52c7b46b0a155a69fbd84f6b7ca20662 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Sun, 26 Feb 2012 21:03:25 -0500 Subject: [PATCH] ex17 extra credit #3 --- ex17-ec.rb | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/ex17-ec.rb b/ex17-ec.rb index 8ed5ed2..b4c5170 100644 --- a/ex17-ec.rb +++ b/ex17-ec.rb @@ -1,23 +1,5 @@ - -from_file, to_file = ARGV -script = $0 - -puts "Copying from #{from_file} to #{to_file}" - -# we could do these two on one line too, how? -input = File.open(from_file) -indata = input.read() - -puts "The input file is #{indata.length} bytes long" - -puts "Does the output file exist? #{File.exists? to_file}" -puts "Ready, hit RETURN to continue, CTRL-C to abort." -STDIN.gets - -output = File.open(to_file, 'w') -output.write(indata) - -puts "Alright, all done." - -output.close() -input.close() +File.open(ARGV.first) do |infile| + File.open(ARGV[1], 'w') do |outfile| + outfile.write(infile.read) + end +end