From: Mark Volkmann Date: 2006-05-18T05:41:04+09:00 Subject: Re: Capturing stdout On 5/17/06, Eric Hodel wrote: > On May 17, 2006, at 12:10 PM, uncutstone wu wrote: > > > Eric Hodel wrote: > >> On May 17, 2006, at 5:26 AM, Mark Volkmann wrote: > >>>> $stdout = stdout > >>> > >>> # Add a write method to this string object. > >>> def dest.write(data); self << data; end > >> > >> How is this better than using StringIO? > > > > IMHO, by using StringIO, you pay for something useless in this case > > but > > maybe usefule anywhere else. I mean StringIO has many methods(e.g. > > read,close,rewind) besides write , but "def dest.write....." has just > > the function you want. > > You're confusing unused with useless. I almost never use Hash#index > but that doesn't make it useless. > > > 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. -- R. Mark Volkmann Object Computing, Inc.