On Tue, Oct 15, 2002 at 01:41:47AM +0900, Matthias Veit wrote:
> class A
>   def self.doit
>     puts "bla"
>   end
>   class Inner
>     def a 
>       A.doit
>     end
>   end
> end
> class B < A
>   def self.doit
>     puts "foo:
>   end
> end
> A::Inner.new.a
> B::Inner.new.a
> 
> will print:
> bla
> bla
> 
> If I could express something like <OuterClass>.doit that would
> be defined in A and is refineable. I do not know, if there is
> such a construct - I think not.
> But perhaps there is a simple solution to circumvent the absolute
> path to make this work??

Try this:

class A
  def self.doit
    puts "bla"
  end

  class Inner
    def outer 
      cls = self.class.to_s.split(/::/)[-2]
      Module.const_get(cls)
    end
    
    def a
      outer.doit
    end
  end
end

class B < A
  def self.doit
    puts "foo"
  end

  class Inner < A::Inner
  end
end

A::Inner.new.a
B::Inner.new.a

bla
foo


You still need to declare Inner inside B somehow, i.e. apparently
inheriting will bring A's methods into subclass but not A's inner
classes.

HTH

Massimiliano