Pra*_*dra 0 ruby file fclose learn-ruby-the-hard-way
filename = ARGV.first
txt = open filename
puts "Here's your file #{filename}:"
print txt.read
puts "Type the filename again: "
file_again = $stdin.gets.chomp
txt_again = open file_again
print txt_again.read
close(txt)
close(txt_again)
Run Code Online (Sandbox Code Playgroud)
程序运行正常,直到结束,但在打印第二个文件的内容后立即崩溃标题错误消息.
我使用(.class)检查了txt,txt_again并确认它们都是File对象.为什么不靠近工作?