shell - Ruby gets method throws an exception when arguments are passed from the console -
i have experienced odd behavior code below:
require 'csv' $debug = argv.empty? ? false : argv[0] #global debug flag. class phonebook #class code here etc etc end phonebook.start_dir = "file-io-samples/phonebooks/" puts "enter phonebook!" name = gets #this problem. puts "using #{name}.." when pass true have $debug set true on execution error name = gets , have no idea why. if don't pass parameters via command line works fine.
this error output:
c:\pickaxe>ruby phonebook.rb enter phonebook! hurrah! works using hurrah! works .. c:\pickaxe>ruby phonebook.rb true enter phonebook! exception `errno::enoent' @ phonebook.rb:62 - no such file or directory - true phonebook.rb:62:in `gets': no such file or directory - true (errno::enoent) phonebook.rb:62:in `gets' phonebook.rb:62:in `<main>' c:\pickaxe> if need can post class definition, don't think it's part of problem.
gets reads stdin if no arguments passed, , file passed argument otherwise. passing argument true, ergo gets tries read file named true, apparently doesn't exist.
this first sentence of documentation of gets:
returns (and assigns
$_) next line list of files inargv(or$*)
Comments
Post a Comment