0
Ruby中的新手和一般编程。Ruby - '读取':无法将字符串转换为整数
我想写入一个文件,然后打印我写到终端中的文件。
filename = ARGV.first
script = $0
puts "Would you like to read the file?"
puts "If you want to, hit RETURN."
puts "If you don't want to, hit CTRL+C."
prompt = "? "
STDIN.gets
puts "Opening file..."
target = File.open(filename, 'w+')
puts "Reading file..."
puts target.read()
puts "Blank, huh?"
print "Write something: "; line1 = STDIN.gets()
print "A little more: "; line2 = STDIN.gets()
target.write(line1)
target.write(line2)
puts "Let's read it now."
puts target.read()
的代码运行,直到我到最后一行,此时下面的错误被抛出:
exl16_2.rb:26:in `read': can't convert String into Integer (TypeError)
from exl16_2.rb:26:in `<main>'
不知道这意味着什么的什么,我试图做上下文(内打印出所写的内容)。
我正在运行1.9.3。倒带完美地工作,感谢您的帮助。 – Cat