On Mon, 12 Jun 2006, James Edward Gray II wrote:

> Oh well, to each their own.
>
> I prefer the nested module approach because:
>
> 1.  I can envision the threads here where we try to explain when to define 
> class methods with and without the method.
> 2.  It has a been a common Ruby idiom for literally years, so history works 
> in our favor.
>
> James Edward Gray II

+1

i use this already, it's very flexible and does 'the right thing':


     harp:~ > cat inheritable.rb
     module Inheritable
       Inherit = lambda do |this, other|
         cm = this.const_get 'ClassMethods' rescue nil
         im = this.const_get 'InstanceMethods' rescue nil
         other.extend cm if cm
         other.module_eval{
           include im if im
           extend RecursiveInherit
         }
       end

       module RecursiveInherit
         def included other
           Inherit[self, other]
           super
         end
       end

       extend RecursiveInherit
     end


     if $0 == __FILE__
       module M
         include Inheritable
         module ClassMethods
           def foo() 42 end
         end
       end
       class C
         include M
       end
       p C.foo



       module A
         include Inheritable
         module ClassMethods
           def bar() 'forty-two' end
         end
         module InstanceMethods
           def foobar() 42.0 end
         end
       end
       module B
         include A
       end
       class K
         include B
       end
       p K.bar
       p K.new.foobar
     end


     harp:~ > ruby inheritable.rb
     42
     "forty-two"
     42.0


perhaps a simple RCR for inheritable.rb?

-a
-- 
suffering increases your inner strength.  also, the wishing for suffering
makes the suffering disappear.
- h.h. the 14th dali lama