From: Nick Sieger Date: 2007-03-27T13:18:10+09:00 Subject: Re: How do I implement the Unix 'tee' function for $stdout? On 3/26/07, Larry Fast wrote: > Nick Sieger wrote: > > Have a look at the CI::Reporter::OutputCapture class > > at line 11, and its usage on line 50: > > http://tinyurl.com/29rhqj > > Thanks Nick, > This is *almost* what I want. I want to MERGE $stdout, $stderr and my > debugging output. If I change @captured_io to @@captured_io and move it > outside Initialize, does everything else stay the same? > > The only changed section is then: > class OutputCapture < DelegateClass(IO) > def initialize(io, &assign) > super > @delegate_io = io > @assign_block = assign > @assign_block.call self > end > > @@captured_io = StringIO.new > > Also, in your invocation on line 50, is {|io| $stdio = io} only used for > resetting $stdout back to normal. Nothing else? For the initial replacement as well as the resetting back to normal, see the #initialize method where it is also used. Seems like your mutation to use a @@class var should work fine. /Nick