From: Hongli Lai Date: 2007-10-13T03:37:36+09:00 Subject: Re: StringIO is not IO? Eric Mahurin wrote: > Since StringIO doesn't use IO to base its implementation, it is not an IO. > > Why does it matter? If you use standard duck typing, it shouldn't. > Class hierarchy doesn't matter with duck typing. Classes are just an > implementation detail with duck typing. You are best off not looking > #is_a?, #respond_to?, etc. Just assume the object can do the methods > you'll be using and use. Well, some of my code can write its output to a file (specified by a filename string) or to an IO object. So my code first checks whether output.is_a?(IO), which is not the case. RMagick seems to do the same thing. I tried making RMagick write its output to a StringIO, but that failed because it thought it isn't an IO object. I spent quite some time on debugging these two problems, and I guess that am not the first one. Finally, when one thinks about it logically, StringIO *should* be an IO. There's even the word 'IO' in its class name. So why not do an 'include IO' in StringIO? That would solve a lot of problems and make the class hierarchy more logical.