在Ruby中,我无法将get.to_i与ARGV参数组合
所以,我刚刚了解了ARGV和参数,我正在尝试在同一个脚本中组合gets.to_I(或gets.chomp)。但这不会发生。有什么建议吗在Ruby中,我无法将get.to_i与ARGV参数组合,ruby,argv,Ruby,Argv,所以,我刚刚了解了ARGV和参数,我正在尝试在同一个脚本中组合gets.to_I(或gets.chomp)。但这不会发生。有什么建议吗 a, b, c, d, e, f = ARGV puts "you will first go to point #{a}, then #{b}, then #{f}, finishing off with #{e} and finally #{d}." print "Give me a number: " time = gets.to_i puts "y
a, b, c, d, e, f = ARGV
puts "you will first go to point #{a}, then #{b}, then #{f}, finishing off with #{e} and finally #{d}."
print "Give me a number: "
time = gets.to_i
puts "you can start at #{time}"
我一直收到以下错误消息:
Give me a number: ex13.rb:12:in `gets': No such file or directory @ rb_sysopen - alpha (Errno::ENOENT)
from ex13.rb:12:in `gets'
from ex13.rb:12:in `<main>'
给我一个数字:ex13.rb:12:in'get':没有这样的文件或目录@rb\u sysopen-alpha(Errno::enoint)
从ex13.rb:12:in'get'
从ex13.rb:12:in`'
在不将get.to_I添加时,我得到的输出是:
“您将首先到达alpha点,然后是bravo点,然后是foxtrot点,最后是echo点,最后是delta点。”
ARGV
看起来像一个数组,但它的行为与一个数组并不完全相同。除非先删除第一个参数,否则无法访问第二个参数。如果您按照以下方式重写代码,则代码可以正常工作:
a, b, c, d, e, f = (0..5).map { ARGV.shift }
puts "you will first go to point #{a}, then #{b}, then #{f}, finishing off with #{e} and finally #{d}."
print "Give me a number: "
time = gets.to_i
puts "you can start at #{time}"
你的脚本没有产生任何错误。看起来不像是同一个问题。如果是的话,它没有帮助我解决问题。我无法解释我的问题与假设的重复问题有何不同。