Using Kernel.const_get() to dynamically create instances seems
to screw up their idea of STDIN. I’m probably missing something
obvious, please can someone enlighten me?
-Sample output:-----------------------
0rasputin@lb:roxo$ ./confused.rb
Rev would like a string:
teststr
rtstset
Echo would like a string:
wibble
wibble
0rasputin@lb:roxo$ ./confused.rb Rev Echo
Rev would like a string:
./confused.rb:13:in gets': No such file or directory - "Rev" (Errno::ENOENT) from ./confused.rb:13:inecho’
from ./confused.rb:22
from ./confused.rb:22:in `each’
from ./confused.rb:22
Using Kernel.const_get() to dynamically create instances seems
to screw up their idea of STDIN. I'm probably missing something
obvious, please can someone enlighten me?
it has nothing to do with const_get, remove the line
svg% ri Kernel::gets
----------------------------------------------------------- Kernel::gets
gets( aString=$/ ) -> aString or nil
···
------------------------------------------------------------------------
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. Returns nil at end of file. The optional argument
specifies the record separator. The separator is included with the
contents of each record. A separator of nil reads the entire
contents, and a zero-length separator reads the input one paragraph
at a time, where paragraphs are divided by two consecutive
newlines. If multiple filenames are present in ARGV, gets(nil) will
read the contents one file at a time.
ARGV << "testfile"
print while gets
produces:
This is line one
This is line two
This is line three
And so on...
svg%
If you give it arguments, it will try to read from these files
Using Kernel.const_get() to dynamically create instances seems
to screw up their idea of STDIN. I’m probably missing something
obvious, please can someone enlighten me?
it has nothing to do with const_get, remove the line
svg% ri Kernel::gets
----------------------------------------------------------- Kernel::gets
gets( aString=$/ ) → aString or nil
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
^^^^
KERRRR-CHUNK. (sound of very large penny dropping).
Thank you very much indeed.
···
svg%
If you give it arguments, it will try to read from these files
You want IO#gets rather than Kernel::gets
–
Nobody can be exactly like me. Sometimes even I have trouble doing it.
– Tallulah Bankhead
Rasputin :: Jack of All Trades - Master of Nuns