From: uncutstone wu Date: 2006-05-18T11:03:10+09:00 Subject: Re: Capturing stdout Mark Volkmann wrote: > On 5/17/06, Eric Hodel wrote: >> > >> >> No. Using StringIO is more robust and more maintainable than using a >> String with custom methods. If I want to puts or print then I have >> to add those methods. If I just used StringIO I won't have to do >> anything. > > You don't have to add a puts method to the String object in order to > have puts calls append to it. puts ends up calling write. I assume > print does the same, but I'm not sure. Yes, print does the same. main.rb: strio = "" def strio.write(data) self << data end $stdout = strio load 'expansion.rb' $stdout = STDOUT puts "Get: #{strio}" expansion.rb print "hello" result: Get: hello -- Posted via http://www.ruby-forum.com/.