「Ruby を難しい方法で学ぶ」に取り組んでいますが、次のサンプル ファイルを実行しようとすると、未定義のメソッド 'close' エラーが発生します: http://ruby.learncodethehardway.org/book/ex17.html
私のコードは、具体的には次のとおりです。
from_file, to_file = ARGV
script = $0
puts "Copying from #{from_file} to #{to_file}."
input = File.open(from_file).read()
puts "The input file is #{input.length} bytes long."
puts "Does the output file exist? #{File.exists? to_file}"
puts "Ready, hit RETURN to contine, CTRL-C to abort."
STDIN.gets
output = File.open(to_file, 'w')
output.write(input)
puts "Alright, all done."
output.close()
input.close()
「output.close()」が正常に動作しているように見えるため、受け取るエラーは最後の行「input.close()」のみです。参考までに、既存の入力ファイルを使用して、新しい出力ファイルを作成しています。
前もって感謝します。