ruby - Kernel#gets attempts to read file instead of standard input -


i'm rather new ruby, , today wrote application can pass arguments via argv. inside application, want able use "gets". problem is, every time try so, error.

here's simple script shows problem:

print "say something! " input = gets 

if i'd call this:

$ ruby script.rb arguments 

i error:

script.rb:2:in `gets': no such file or directory - (errno::enoent) script.rb:2 

hope able me solve this, can continue ruby journey. :)

edit: aware "gets" won't retrieve arguments passed file. "gets" query user input. want able use both these methods inside application.

if there arguments, default gets method tries treat first 1 file , read that. read $stdin in such situation, have use explicitly:

print "say something! " input = $stdin.gets 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -