ファイル I/O

第二引数に指定されたファイルから読んで、第三引数に指定されたファイルに書く (Append)

lesson005.rb


dummy, source, target = ARGV

open(source, 'r') do |s|
open(target, 'a') do |t|

s.each do |line|
t.puts line
end

end
end

実行結果

C:\>ruby c:\study\ruby\chapter003\lesson005.rb dummy c:\study\ruby\chapter001\le
sson003.rb c:\study\ruby\chapter001\test.txt

C:\>type c:\study\ruby\chapter001\test.txt
var1 = "Hello";
var2 = "World";
print var1, ", ", var2, "!", "\n";
var1 = "Hello";
var2 = "World";
print var1, ", ", var2, "!", "\n";