From: David Alan Black Date: 2002-04-11T05:36:06+09:00 Subject: RE: OO/Ruby Terminology Hi -- On Thu, 11 Apr 2002 james@rubyxml.com wrote: > > From: Chris [mailto:chris@cmb-enterprises.com] > > > > I think the best way to introduce someone to OO programming is to first > > explain that a method/feature/message/etc. is what an object "can do". > > This is where I see a chance for confusion. Message != method. Ruby > objects can respond to arbitrary messages in a variety of ways, and yet the > object may have no corresponding method. > > Most of the time, though, there is a one-to-one correspondence. For > example, in Java, you can't write myFoo.arbitraryMessage unless myFoo > really has a method called arbitraryMessage. There are ways to allow for > arbitrary messages, but the syntax is ugly; Java doesn't seem all that > conducive for separating message from method. > > With Ruby, I can have > #----------------- > class Foo > def method_missing(methID, args=nil) > methID.id2name > end > end > > my_foo = Foo.new > puts my_foo.bar # Acts as if there is a bar method > #----------------- > > > I'm inclined to think it incorrect to say that that the code is calling > my_foo's bar method. > Am I being pedantic, or wrong? I guess I'd tend to think of it as *trying* to call my_foo's bar method -- as opposed to being a case of message-sending that has no connection to method-calling. #method_missing is sort of in the exception-handler family, at least in spirit. If in every other respect it were the case that message == method, then I wouldn't think the existence of method_missing would change that. However... there's also things like: obj.some_attr = 123 where there may or may not be a #some_attr method, but the real point is that there's a #some_attr= method (which does not correspond exactly by name to the message name). David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav