From: Ron Jeffries Date: 2002-02-14T02:14:41+09:00 Subject: Re: qualms about respond_to? idiom On Wed, 13 Feb 2002 16:28:59 GMT, David Alan Black wrote: >OK -- but does this suggestion mean that you would see the >"responds_to?" idiom as a sign that something's wrong with the code? >Actually, this all started for me with my work on NQXML::Dispatcher, >when I was originally branching on type: > > if e.is_a? NQXML::Tag > if e.startTag? > ... > > >and got enlightened on IRC about not branching on type or depending on >type in Ruby :-) So I've learned to think of branching-on-type as a >sign that something needs to be fixed; now I'm wondering whether the >responds_to? idiom should be viewed similarly (rather than as an >acceptable rewrite of branching on type). Yes. I think that use of "responds_to?" is in general a fairly intense code smell. Ronald E Jeffries http://www.XProgramming.com http://www.objectmentor.com I'm giving the best advice I have. You get to decide whether it's true for you.