我正在尝试从 Zed Shaw 的 Learn Ruby the Hard Way 练习 15 中运行此代码:
filename = ARGV.first
prompt = '> '
txt = File.open(filename)
puts "Here's your file: #{filename}"
puts txt.read()
puts "I'll also ask you to type it again:"
print prompt
file_again = STDIN.gets.chomp()
txt_again = File.open(file_again)
puts txt_again.read()
每次我运行它时,我都会收到一条错误消息,上面写着:
ex15.rb:4:in `initialize': can't convert nil into String (TypeError)
from ex15.rb:4:in `open'
from ex15.rb:4
到底是怎么回事?我无法让这段代码工作!