On Fri, Feb 21, 2014 at 1:14 PM, Arup Rakshit <lists / ruby-forum.com> wrote:

> Sometimes, there is a need, that before calling a method on an object,
> we should check, **if the object responds to a method**.
>
> we can do the same either way -
>
> ob.meth if ob.respond_to?(:meth)
>
> or
>
> ob.meth rescue rescue NoMethodError
>
> Which one is considered as best-practice and why ?

It depends on the situation, and there are several other ways.  You
can override method_missing to not raise an error, you can use try,
you can use a null object (which certainly keeps the calling code
cleanest), and probably a few others that aren't springing to my mind
immediately....

-Dave

-- 
Dave Aronson, the T. Rex of Codosaurus LLC (www.codosaur.us);
FREELANCE SOFTWARE DEVELOPER, AVAILABLE AS OF MARCH 1st 2014;
creator of Pull Request Roulette, at PullRequestRoulette.com.