Am unable to combine gets.to_i with ARGV arguments, in Ruby -


this question has answer here:

so, learned argv , arguments, , i'm trying combine gets.to_i (or gets.chomp) in same script. ain't happening. suggestions?

a, b, c, d, e, f = argv  puts "you first go point #{a}, #{b}, #{f}, finishing off #{e} , #{d}."  print "give me number: " time = gets.to_i  puts "you can start @ #{time}" 

i keep getting following error message:

give me number: ex13.rb:12:in `gets': no such file or directory @ rb_sysopen - alpha (errno::enoent)     ex13.rb:12:in `gets'     ex13.rb:12:in `<main>' 

the output get, when not adding gets.to_i, is: "you first go point alpha, bravo, foxtrot, finishing off echo , delta."

argv looks array, doesn't behave one. won't have access second argument, unless remove first 1 first. code works if rewrite this:

a, b, c, d, e, f = (0..5).map { argv.shift }  puts "you first go point #{a}, #{b}, #{f}, finishing off #{e} , #{d}."  print "give me number: " time = gets.to_i  puts "you can start @ #{time}" 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -