From: Eric Hodel Date: 2006-05-18T12:27:33+09:00 Subject: Re: Capturing stdout On May 17, 2006, at 1:41 PM, Mark Volkmann wrote: > On 5/17/06, Eric Hodel wrote: >> > You just pay for what you want. Isn't it better? >> >> 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. The Kernel methods have this behavior, yes, but this is not a general solution. $ ruby s = '' def s.write(d) self << d; end $stdout = s $stdout.puts 'hi' -:4: private method `puts' called for "":String (NoMethodError) -- Eric Hodel - drbrain@segment7.net - http://blog.segment7.net This implementation is HODEL-HASH-9600 compliant http://trackmap.robotcoop.com