ruby - Using "gets" for user input -



ruby - Using "gets" for user input -

i have code:

def main() info = [] csv.foreach('test.csv') |row| info.push(row) end headers = info.shift param = argv[0] if param.downcase == "action1" ans = func1(info, headers) elsif param.downcase == "action2" puts "enter value:\n" extra_param = gets.chomp p func2(info, headers, extra_param) else puts "invalid parameter" end end

when seek run (with 'action2' command line argument), error says:

:in `gets': no such file or directory - action2 (errno::enoent)

from have gathered, seems "gets" in case not waiting user input trying utilize command line argument passed in open/read file. how create "gets" instead wait user input , disregard command line argument?

instead of doing param = argv[0], param = argv.shift remove argument argv. otherwise, utilize $stdin.gets if don't want worry argv having input.

kernel#gets read argv, if have passed arguments without flushing them, you'll above error, since it's trying read file named argument.

ruby

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -