From: daz Date: 2005-10-28T14:02:04+09:00 Subject: Re: Stuck with modules/classes/inheritance Kev Jackson wrote: > given: > > test.rb : > > require 'b' > > b = B.new > > > lib/base.rb: > > module A > class Base > end > end > > lib/b.rb: > > module A > class B < Base > end > end > > > Why do I get > > /lib/b.rb:2: uninitialized constant A::Base (NameError) > from test.rb:1:in `require' > from test.rb:1 > > ? > > This is a stripped down version of what I want to do (ie organize my > code into a module, but still keep classes in separate files, have a > base class and inherit). > > It's probably something trivial, but at the moment I'm stuck - any help > would be (as always) greatly appreciated > > Kev > Hi Kev, require 'b' loads /and runs/ b.rb immediately. You have at the top: module A class B < Base end end Base is defined later, so you need to organise the require order (?). Then b = A::B.new (as Eric said) HTH, daz