> -----Original Message----- > From: Eric Mahurin [mailto:eric.mahurin / gmail.com] > Sent: Friday, October 12, 2007 12:16 PM > To: ruby-core / ruby-lang.org > Subject: Re: StringIO is not IO? > > > On 10/12/07, Hongli Lai <h.lai / chello.nl> wrote: > > According to irb, > > > > >> StringIO.is_a?(IO) > > => false > > > > This seems illogical to me. Is this intentional? If so, why? > > 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. This is actually the one case where duck typing burned me. In the spreadsheet library I was using IO#fileno, so that users could pass their own IO objects if they wanted. Well, it turned out some people were trying to stream the results to their web browsers using StringIO. Does StringIO respond to fileno? Yes. Does it work? No. It returns nil. Just thought I'd share that little anecdote with y'all. :) Regards, Dan This communication is the property of Qwest and may contain confidential or privileged information. Unauthorized use of this communication is strictly prohibited and may be unlawful. If you have received this communication n error, please immediately notify the sender by reply e-mail and destroy all copies of the communication and any attachments.