対象の行を元の6行とは反対の1行に減らすように求められました。なぜ私が間違いを起こしているのかの背後にある説明?Rubyスクリプトの繰り返しを減らそうとしています
filename = ARGV.first
puts "We're going to create #{filename}"
puts "If you don't want that, hit CTRL-C (^C)."
puts "If you do want that hit RETURN (Enter)"
$stdin.gets
puts "Opening File..."
target = open(filename, 'w')
puts "Truncating the file."
target.truncate(0)
puts "Now I'm going to ask you for three lines."
print "line 1: + line 2: + Line 3:"
line1 = $stdin.gets.chomp
line2 = $stdin.gets.chomp
line3 = $stdin.gets.chomp
puts "I'm going to write these to the file."
target.write(#{line1}\n#{line2}\n#{line3})
puts "And finally, we close it."
target.close
どのようなエラーが表示されますか? – benbot
ex16.rb:27:構文エラー、予期しないtIDENTIFIER、期待 ')' target.close) ^ ex16.rb:27:構文エラー、予期しない ')'、期待入力終了 target.close) ^ – chilledheat
'target'はIOオブジェクトなので(sawaの特に熱心な編集の後では少し難しい)、もっと良い解決策は[IO#puts'](http://ruby-doc.org/core -2.3.0/IO.html#method-i-puts)。複数の引数をとり、 'target.puts(line1、line2、line3)'の後に自動的に改行を追加します。 –