This little library implements or better simulates multiple inheritance for ruby without the use of mixins. It is based on work by Maurice Codik and was extended by myself to use python's method resolution order and a large portion of ruby's metarogramming facilities.
Multiple Inheritance without MixIns 0
I'm currently working on multiple inheritance simulation for Ruby. My work is based on Maurice Codik's start from last year. I'm trying to add all meta programming features seemlessly, such as ancestors, super and meta callbacks method_added. While Maurice didn't care about method resolution order, I hope to implement Python's.
Along the way I'm getting warm with RSpec to ensure a well defined behaviour of my extensions.
Done: I spent some hours on it today and I am willing to release it to the public. The basic implementation idea didn't change, but I had to change some strategies in order to implement a reasonable method resolution order. This may also mean, that the performance of message sends suffers from these changes. So this library is not meant to work in public software, but it may be used to fool around and see what is possible.
My main targets where a reasonable method resolution order (namely Python-2.3's) and the functionality of the main meta object and reflection protocol of ruby (see this post for some examples).
Download
You may download the library in its very first version (0.1) here. The RSpec file is available separately.
Specification
I have used Rspec to state my wishes.
Assuming, that A and B are direct subclasses of Object
A subclass of A and B
- should answer with
[A, B]when sendedsuperclasses - should not list constants defined in its superclasses, when sent
constants - should not answer true to
const_defined?for constants defined inAorB - should answer true to
const_defined?for constants defined in it - should list methods of its superclasses in
instance_methods( true )
The ancestors of a subclass of A and B
- should contain
A,BandObject - should have
Aas first element - should not include double entries
- should contain
AbeforeB - should contain
BbeforeObject
An instance of a subclass of A and B
- should be kind of its class
- should be kind of its super classes
- should be kind of its super super classes
- should prefer its own methods over inherited ones
- should be able to call inherited methods
- should be able to combine inherited calls
- should prefer methods defined in
AoverObject's - should prefer methods defined in
BoverObject's - should prefer methods defined in
AoverB's (left first) - should be able to use
method_missing - should be able to use
method_missingin one of its parents - should answer
respond_to?( 'some method in A' )withtrue - should answer
respond_to?( 'some method in B' )withtrue - should answer
respond_to?( 'some method in Object' )withtrue - should be able to access constants defined in superclasses directly
- should be able to use
const_missing - should list methods of its superclasses in
methods
When A and B are subclassed by a class, they
- should be informed via
self.inherited( subclass )
I did not yet work on instance or class variables, as well as the behaviour of private or protected methods (who uses them anyway?). Please send me your ideas or bug reports. I am sure, that this is far from perfect.
