Chris Roos wrote:
> I'm no doubt missing something obvious but I found this a little
> confusing.  I would have expected the constant lookup to start in Bar
> and therefore succeed.  Instead, it appears to start in Base where Foo
> is not defined.
> 
> class Base
>  def foo
>    p Foo
>  end
> end
> 
> class Bar < Base
>  class Foo
>  end
> end
> 
> Bar.new.foo
> # ~> -:3:in `foo': uninitialized constant Base::Foo (NameError)
> # ~>     from -:12
> 
> Can anyone explain what is happening please?

Foo is not in the scope of Base so it cannot be looked up the way you 
did it.  See Matz's explanation how to access it nevertheless. 
Generally this form of dependency is not desirable, because the base 
class should be self contained and not depend on any sub classes.  In 
Java you could make Base abstract and add an abstract method that will 
return a Class instance - but in Ruby there are no abstract classes.

Kind regards

	robert