On Wed, Aug 21, 2002 at 06:17:19AM +0900, Gray, Jeff wrote:
>   Thanks for the suggestion!  I have installed stringio.rb but am having
> problems with the redir method.  I get 'uninitialized stream' errors in both
> my code and your unit tests, on many flavors of Ruby (windows/linux, 1.6.5
> through 1.7.2):

That's because, for some reason now known only to the gods, I made
StringIO inherit from IO.  It does not support opening modes and all
that, so I can't see why I did that.  Oh well, age...  Anyway, just
nuke the `< IO' in the first line and it should work fine for what it
was written for (testing user interaction, you name it ;-)).

BTW, I agree with Nat that a class should be free from references to
the external world such as the $stdin and $stdout implicit in puts and
gets.  I also should add that I walked that path when writing classes
explicitely aimed at user I/O, and writing and reading lots of calls
to @stdin.gets and @stdout.gets quickly became such a pain that the
feel of good engineering could not balance it.  Depending on the
purpose of your classes, YMMV, and I'd be the first to cut
away $stdin's and $stdout's in a non-I/O intensive class.


Massimiliano