From: Hugh Sasse Staff Elec Eng Date: 2002-02-14T00:09:36+09:00 Subject: Re: qualms about respond_to? idiom On Wed, 13 Feb 2002, David Alan Black wrote: > Hi -- > > I'm cool with Ruby's emphasis on object interface rather than type. > The only thing is... I just can't get myself to be happy about this > idiom: > > if obj.respond_to? "method" then obj.method end > > I'm not sure how to express what I don't like about it -- but I guess > the sheer repetitiveness of it, mainly. It always looks and feels > like a kind of workaround to me, or like something is being done > manually that should somehow just happen. Also the failure of the if clause raises the question about what to put in the else clause. TRCR - tentative ruby change request: define respond_to_these? accepting an array as its first parameter, then one could test all the methods at once, to check the interface before you set out. define Object::these_respond_to? accepting a hash as the first parameter, then one could do Object::respond_to?({ aRegexp => "match", aString => ">>", anInstance => "each"}) and test a bunch of parameters at the outset. > > David Hugh