[Nitro] Better than classinherit.rb!

TRANS transfire at gmail.com
Tue Apr 11 00:25:58 EDT 2006

On 4/10/06, itsme213 <itsme213 at hotmail.com> wrote:
> Nice!
> A couple of questions:
> - Breaks if mod is enhanced with singleton methods after interlusion?

Yes that's true (seemingly there is always a shortcoming no matter
what you do!) So this solution, while robust, suffers from
non-dynamics. I tried a fix this shortcoming this evening but the
solution opens up an infinite loop --and is getting increasingly more
hackish :-(. I'll see if I can't close the loop on Thursday.

Beyond that I should point out that I quickly was able to adjust
Ruby's source code to this --it's simply a matter of letting Ruby
extend using an eigenclass.

  class X
    extend (class << FooModule; self ; end)

which actually leads to including classes just like one does modules
(although it could be limited to one method like #interlude easily
enough) . It works perfectly and all Ruby's test cases pass with the
change in place. It's really a shame Matz has some sort of theoretical
grudge against this possibility. How many man-hours could have been

> - Do you know any hooks that would enable the inverse operation: R.is_not(M)

You mean uninclude? I don't think it's possible. You can always copy
and undefine methods but obviously that's not the same thing. The Ruby
source code itself has a problem here in the way it works, so I'm not
sure it would ever be possible --it is related to the Dynamic Module
Problem: Module's themselves are only dynamic upto two layers of
inclusion for any including object after it has been instantiated).

> There are advantages to your older ClassMethods (and less so
> InstanceMethods) convention, since they require a module holding methods
> uniformly for either classes or 'other' objects. I have been doing the
> following. Could probably be simplified further by someone more expert than
> I ...

Yes. That has advanages of it's own. Unfortuately it has it's own
corner casses too --it won't work with cattr for instance. At this
point --and maybe forever, all one can do is pick the hack that works
best for the given situation (and pray everyone's choices don't come
crashing down on each other ;-)


More information about the Nitro-general mailing list