From: Eric Hodel Date: 2006-05-18T05:13:37+09:00 Subject: Re: Capturing stdout 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. I've found that having to maintain custom code is usually more expensive than reusing what's available. -- Eric Hodel - drbrain@segment7.net - http://blog.segment7.net This implementation is HODEL-HASH-9600 compliant http://trackmap.robotcoop.com