From: Tomasz Wegrzanowski Date: 2001-12-30T13:25:25+09:00 Subject: [ruby-talk:29700] Re: extending method of class A to support arguments of class B by promoting `self' to class B On Sat, Dec 29, 2001 at 06:08:49PM +0900, Yukihiro Matsumoto wrote: > Hi, > > In message "[ruby-talk:29610] Re: extending method of class A to support arguments of class B by promoting `self' to class B" > on 01/12/29, Tomasz Wegrzanowski writes: > > |> Otherwise, if you mean generic classes, there's no such > |> framework now. > | > |It would be really nice if such thing were added. > > Define "such thing". And convince me it's nice. > > matz. Such-thing is defined more by problem it tries to solve than by solution. Not every relation can be put into "object-oriented" form, where one of involved objects logically-dominates all others. Often, relation involve more than one object at logically-equal-rights. The most obvious example are mathematical relations, like addition and substraction, where none of objects is logically-more-important than others. It doesn't happen only in case of symmetrical relations - substraction is obviously asymmetrical, but none of the objects dominates another. Such-thing would allow one to provide rules of interaction on any side of relation. Now, in most object-oriented-languages, including Ruby, NewClass.relation(OldClass) is much easier to define than OldClass.relation(NewClass), although their nature is alike. Such-thing could be based on TypeError exception mechanism. It would be possible to registere catching functions: register_catch_typeerror_function(ourclass, savingmethod, savedclass, savedmethod) that would be called in case of such exceptions. Example: register_catch_typeerror_function(Complex, :real_plus_complex, Real, :+) :real_plus_complex would be method of real that is called if :+ fails with typeerror and one of its arguments is Complex. Convincing anyone that this particular solution is good will be hard, but I hope you agree that there is a problem.