On Wednesday 22 April 2009 05:43:06 Robert K. 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,
still a lot more duck-friendly than kind_of?, and is probably the
choice, unless it really would be exceptional for it not to have that
But yes, it’s true – overriding respond_to? gets you partway there, but
never know how an object is going to respond to a method until you call
After all, from your perspective, there’s really no difference between
raise NoMethodError …
Once you consider that, it becomes obvious that there may be a situation
respond_to? either can’t be reliable, or would be expensive (for
you’re doing something like DRb).