From: "T. Onoma" Date: 2003-12-24T04:09:50+09:00 Subject: Re: Copying methods from one class to another On Tuesday 23 December 2003 09:51 am, Ian Hobson wrote: > This still does not answer the question of why? (At least for me), so > I'm jumping in here are asking it again! > > When you can simply extend class A with any new method you need, why do > you want to create a subclass and pretend it is the class you started > with? James' answer is correct. We have been discussing Aspect Oriented Programming for Ruby in-depth, the main feature of which is method wrapping (known as *advice* in AOP terms). Currently method wrapping is generally approached via method aliasing, but a better way comes from the realization that subclassing already entails method wrapping. All that is needed is a way to *annonymously subclass*. class A < A is one way to to do this, but requires moving method definitions into the super class when they are subsequently defined. It is not a perfect solution, and was merely used in one possible test implementation. That's a highly concise explination. If you are interested in this, understanding more about it, or other related topics, please join the suby-muse mailing list. It's a reasonably low traffic list, so no worries of being bombarded with emails. http://lists.berlios.de/mailman/listinfo/suby-muse Currently, the discussion has led us into considerations of Multiple Inheritence. It is interesting to note that Ruby is actually but a hair's breath from being a type of MI language. One last note: class A < A can be useful in and of itself for similar reasons. If for instance, one wished to redefine a class as an elaboration on the current class, as opposed to altering the class directly aliasing numerous methods. -- T.