Tom Cloyd
4/22/2009 5:35:00 PM
Jesús Gabriel y Galán wrote:
> On Wed, Apr 22, 2009 at 12:43 PM, Robert Klemme
> <shortcutter@googlemail.com> wrote:
>
>>> Chris Kottom wrote:
>>>
>>>> Object#respond_to? doesn't do it for you?
>>>>
>> This is unsafe:
>>
>> irb(main):001:0> o = Object.new
>> => #<Object:0x10171bb8>
>> 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)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~