From: Tom Cloyd Date: 2009-04-23T02:34:41+09:00 Subject: Re: how to test for existence of a method Jes�s Gabriel y Gal�n wrote: > On Wed, Apr 22, 2009 at 12:43 PM, Robert Klemme > wrote: > >>> Chris Kottom wrote: >>> >>>> Object#respond_to? doesn't do it for you? >>>> >> This is unsafe: >> >> irb(main):001:0> o = Object.new >> => # >> irb(main):002:0> def o.method_missing(s,*a,&b) s == :foo ? "yes" : super end >> => nil >> irb(main):003:0> o.respond_to? :foo >> => false >> irb(main):004:0> o.respond_to? "foo" >> => false >> irb(main):005:0> o.foo >> => "yes" >> irb(main):006:0> >> > > Just a question: isn't it good practice to override respond_to? when > you use method missing to handle things, so that it "tells the truth"? > Or is it something people don't usually do? > > Jesus. > > > How would you do this? t. -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist Bellingham, Washington, U.S.A: (360) 920-1226 << tc@tomcloyd.com >> (email) << TomCloyd.com >> (website) << sleightmind.wordpress.com >> (mental health weblog) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~