On Wed, May 30, 2007 at 11:00:14PM +0900, Maurice Gladwell wrote:
> James Gray wrote:
> > On May 30, 2007, at 7:53 AM, dblack / wobblini.net wrote:
> > 
> >> You could of course shoehorn find_by_* into respond_to? for AR
> >> objects, if you don't mind, essentially, writing method_missing twice
> >> (once for real, once as a kind of pseudo-static twin).
> > 
> > I don't really understand this stance.  My opinion is that providing
> > a method_missing() implementation is a convenient way for a
> > programmer to define a lot of dynamic methods.  This increases the
> > messages an object responds to.
> 
> I must agree with James Edward Gray here.
> 
> David's contrived example is of course possible, but highly unlikely in 
> practice; a programmer will generally not code his program into a 
> situation in which he can't be sure whether an object will respond to a 
> particular message sent to it. That's probably a major reason for having 
> Object#respond_to?.

As an edge case, consider a DRb client proxy object. Should respond_to? be
handled locally, or should it be proxied to the server? This involves an
expensive network round trip.

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.

Regards,

Brian.