From: Hal Fulton Date: 2003-12-15T08:39:06+09:00 Subject: Re: All there is to know about Duck Typing (was: inplace assignment) John Carter wrote: > You could invoke any method on any object of any class. > > But what would happen thereafter depended very much on the class of > the instance. > > The default behaviour was system settable, either > * print a debug statement to the log file, or > * Do nothing and just return. > > > For example, the Person object wouldn't have a > "paint_yourself(colour)" method. Thus if you had a mixed bag of > objects, you could tell the whole bag to "paint_yourself( blue)", the > drawable objects would paint themselves blue and the people would just > do nothing. > > In practice mixed bags of objects were not all that common though, but > if duck typing is more accessible they may start to be. > > It's sort of like the default parameter on Hash.new what do you want > hash[unknown_key] to be today? What do you want > object.unknown_method() to do today? Hmm. I'm uncertain how good this idea is in general practice. But unless I'm missing something, it would be trivial to do this in Ruby, simply by defining method_missing for every class. Hal