Brian Candler wrote:
> In many cases it may be cheaper to attempt the call and to rescue a
> NoMethodError, than to have 'respond_to?' perform almost as much work as 
> the
> call you're testing.

That's certinly true, but the rescue technique you describe is not a 
substitute for a working #respond_to?. You're actually sending the 
message, not asking the object whether it will respond to it.

These are two completely different operations. The only relevant 
solution here would be if you aspired to emulate Object#respond_to? by 
checking if the call raises NoMethodError, but that's infeasible because 
method call commonly have side effects and/or are destructive.

--
M.

-- 
Posted via http://www.ruby-forum.com/.