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?.

In practice, and certainly in the Rails' find_by_* case, you have a 
well-defined  range of messages to which an object will respond, known 
already at development time. I don't know of a single real-life example 
in which a programmer doesn't know at development time the entire range 
of messages his objects might respond to. And Rails - with all its magic 
- notwithstanding.

--
M.

(Of course, even if there would be an exception to that rule, in which 
we really cannot delimit - for reasons unimaginable - the range of 
messages to which the object will respond to at runtime - that rare and 
probably bizarre case would not obviate the usefulness of the other 
99.99% more common cases.)

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