Ten Things Every Java Programmer Should Know About Ruby

Lähettäjä: "David A. Black" <dblack@wobblini.net>
Aihe: Re: Ten Things Every Java Programmer Should Know About Ruby

Hi --

> If method_missing handles 'foo', then the object responds to 'foo'.

That's true in an informal sense, but it doesn't capture the practical
relation between #respond_to? and #method_missing -- which is that
#method_missing is what happens to messages that don't correspond to
what the object #respond[s]_to? In other words, one can say that an
object responds to every message, and that no method is truly missing,
but that isn't the whole story of the #respond_to?/#method_missing
mechanisms.

I think it's better to think of it as: an object responds to a certain
set of messages, and if it's sent a message it doesn't respond to,
that's considered an exceptional condition which can be trapped either
with a rescue clause or with the special #method_missing method.

Well, by default #method_missing causes a runtime error. If a
programmer overrides the default behaviour, they should only handle
the methods they need to and raise an error on everything else (which,
of course, may or may not be the case depending on the diligence of
said programmer). Conceptually, then, if an object doesn't raise an
error when invoking 'foo', it's responding to it. Reality tends to
get in the way, though, so your explanation is certainly better in
that respect :slight_smile:

David

E

···

On Sun, 30 Jan 2005, E S wrote:

Well, by default #method_missing causes a runtime error. If a
programmer overrides the default behaviour, they should only handle

                                               ^^^^^^^^^^^^^^^^^^^^^^^

the methods they need to and raise an error on everything else (which,

   ^^^^^^^^^^^^^^^^^^^^^^^

of course, may or may not be the case depending on the diligence of
said programmer).

plruby use #method_missing to emulate #autoload, because it run with
$SAFE = 12 and #autoload is not available in this case with ruby < 1.8

It dont know what is "the methods they need to" :slight_smile:

reality is sometimes a little more complex

Guy Decoux

Hi --

Lähettäjä: "David A. Black" <dblack@wobblini.net>
Aihe: Re: Ten Things Every Java Programmer Should Know About Ruby

Hi --

If method_missing handles 'foo', then the object responds to 'foo'.

That's true in an informal sense, but it doesn't capture the practical
relation between #respond_to? and #method_missing -- which is that
#method_missing is what happens to messages that don't correspond to
what the object #respond[s]_to? In other words, one can say that an
object responds to every message, and that no method is truly missing,
but that isn't the whole story of the #respond_to?/#method_missing
mechanisms.

I think it's better to think of it as: an object responds to a certain
set of messages, and if it's sent a message it doesn't respond to,
that's considered an exceptional condition which can be trapped either
with a rescue clause or with the special #method_missing method.

Well, by default #method_missing causes a runtime error. If a
programmer overrides the default behaviour, they should only handle
the methods they need to and raise an error on everything else (which,
of course, may or may not be the case depending on the diligence of
said programmer). Conceptually, then, if an object doesn't raise an
error when invoking 'foo', it's responding to it. Reality tends to
get in the way, though, so your explanation is certainly better in
that respect :slight_smile:

I'm making a distinction between an object's responding to 'foo'
(which, as you say, it does if it doesn't raise a method missing
error), and the methods that an object tells you it responds to with
#respond_to? I don't think I put it very clearly in my second
paragraph. It might be more like: an object will tell you what
methods it knows itself to respond to, and if it's sent a different
message, that's considered an exceptional condition... and if it's
caught with #method_missing, it will be a response (even though the
object didn't know that it could respond to that message).

Or something :slight_smile:

David

···

On Mon, 31 Jan 2005, E S wrote:

On Sun, 30 Jan 2005, E S wrote:

--
David A. Black
dblack@wobblini.net