Very basic Ruby question


Hello I have a very basic question and a problem that seems like I should be alble to solve easlily myself, but haven´t.

How do I combine gets with ARGV?

If I write the most simple example:

a = gets
puts a

Then run the program like this:

./test argument

gets complains that it can not open the file “argument”. Why does it think I want to open the content of ARGV as a file? I have not specified this.


You did have. From the definition of gets in, for instance, here :

gets : Returns (and assigns to $_) the next line from the list of files in ARGV (or $*), or from standard input if no files are present on the command line.


Thank you!

Seems like quite weird behaviour in gets though. I mean it provides some convenience here, but at the cost of always having to add the prefix $stdin. to get it to explicitly read from stdin.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.