From: skim Date: 2010-07-15T00:56:51+09:00 Subject: Re: Stdout as IO object --00163641692993a2d7048b5b08d1 Content-Type: text/plain; charset=ISO-8859-1 Instead of modifying the global variable $stdout, you could just pass in an instance of StringIO to your method/class. I passed in two instances of StringIO to one of my classes for mocking STDIN and STDOUT. On Wed, Jul 14, 2010 at 03:10, Brian Candler wrote: > Jonathan Bale wrote: > > Okay, real simple question, but somehow I am missing it in the API: how > > do create an IO object that represents stdout? I'm using a certain > > function that receives writable IO objects and I wanted to pass in the > > standard output as a stream. > > When your program starts, the constant STDOUT is an open file descriptor > for STDOUT, and the global variable $stdout also points to it. > > Using the global variable is the recommended approach, as it adds more > flexibility for pointing it to a different object like a StringIO > without having warnings about constants being redefined. > -- > Posted via http://www.ruby-forum.com/. > > --00163641692993a2d7048b5b08d1--