0
我试图截断并写入新的生产线,以一个文件的内容并打印后的空白:红宝石印刷书写线
target = File.open(ARGV.first, 'w')
puts "we are going to clear the file first"
target.truncate(0)
puts "give me 1 line"
line1 = $stdin.gets.chomp
puts "give me another line!"
line2 = $stdin.gets.chomp
puts "we are gonna write the text into the file now"
target.write(line1)
target.write("\n")
target.write(line2)
target.write("\n")
newfile = open(ARGV.first, 'r')
puts newfile.read
puts "we will close the file now"
target.close
然而,红宝石保持印刷空白。我写的文本文件有我输入的文本。我不确定发生了什么事。
即使它是空的,请将您的程序**的输出发布到问题主体中,而不是注释**。如果不知道实际产出与预期产出的关系,我们就会感到无助 – onebree
其次,我改变了你的标签。 RoR是一个没有专注于LRTHW的Web框架。下一次,请选择_correct_标签,它们不一定是SO上最受欢迎的标签。 – onebree