From: David Masover Date: 2009-04-23T06:02:00+09:00 Subject: Re: how to test for existence of a method On Wednesday 22 April 2009 05:43:06 Robert Klemme wrote: > The best approach is to actually invoke the method and deal with > exceptions IMHO (-> duck typing). I think that depends on the situation. If respond_to? is known to work, it's still a lot more duck-friendly than kind_of?, and is probably the easiest choice, unless it really would be exceptional for it not to have that method. But yes, it's true -- overriding respond_to? gets you partway there, but you never know how an object is going to respond to a method until you call it. After all, from your perspective, there's really no difference between class Foo end and class Foo def foo raise NoMethodError ... end end Once you consider that, it becomes obvious that there may be a situation where respond_to? either can't be reliable, or would be expensive (for example, if you're doing something like DRb).