"Christoph Rippel" <crippel / primenet.com> writes:

> ... the current mixin mechanism does not come with built
> in support of instantiation of Module constants  at ``include time''

I have to admit I've lost track of this thread, so this may have come
up before, but you can generate classes with constants parametrically, 
which gives you the same effect. For example:

     class CommonNumberStuff
       def initialize(n)
         @val = n
       end
       # other methods common to all numbers
     end

     def Base(n)
       klass = Class.new(CommonNumberStuff)
       klass.const_set(:BASE, n)
       klass.module_eval <<-EOS
         def baseString
           "\#{BASE}: \#@val"
         end
       EOS
       return klass;
      end

     class HexNumber < Base(16)
     end

     b = 8

     class OctalNumber < Base(b)
     end

     h = HexNumber.new(1)
     puts h.baseString               #=> 16: 1

     o = OctalNumber.new(2)
     puts o.baseString               #=> 8: 2


A superclass can be any arbitrary expression that returns a class
object, so you can construct parent classes on the fly.

Regards


Dave