Hedef hattımı orijinal 6 hattımın aksine bir satıra indirmem istendi. Neden hata aldığımı anlatan bir açıklama var mı? Eğer bir dize yazıyoruz yanaRuby komut dosyasında tekrarlamayı azaltmaya çalışmak
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
Ne tür bir hata alıyorsunuz? – benbot
ex16.rb: 27: sözdizimi hatası, beklenmedik tIDENTIFIER, bekliyor ')' target.close) ^ ex16.rb: 27: sözdizimi hatası, beklenmedik ')', bekliyor sonu girişi target.close) ^ – chilledheat
'Hedef' bir IO nesnesi olduğundan (sawa'nın özellikle hevesli düzenlemesinden sonra söylemek biraz zor), ['IO # puts'] kullanmak daha iyi bir çözüm olabilir (http://ruby-doc.org/core -2.3.0/IO.html # yöntem-i-koyar), birden çok argüman alır ve her biri sonra bir satırsonu otomatik olarak ekler: "target.puts (satır1, satır2, satır3)". –