From: Rick DeNatale Date: 2010-06-15T20:25:30+09:00 Subject: Re: Placement of require() and missing symbols On Mon, Jun 14, 2010 at 9:18 PM, Eric MSP Veith wrote: > With the above code, I get a "missing symbol" error. Placing the "require > 'a/b'" statement within the Foo::A class remedies it. > > Now I'm not quite sure why. I know that require() is a statement like puts > in regards of its execution time, i.e. there's no special treatment in some > parse/compile/whatever phase before the actual execution begins. As such, it > seems logic that I get the missing symbol error with the original code: > Foo::A is not defined when the derivation is made, and as such, putting > require 'a/b' some lines later helps. > > Am I correct with this explanation? Yes > Is there any best practice regarding such a situation? While this example is > constructed, I'm trying to create a namespace hierarchy in which a class on > top mediates several others that live further below the hiearchy, but don't > derive from it. > > I'm open for all kinds of suggestions. Have a look at the Module#autoload, and Kernel#autoload methods These can be a useful 'sword' when trying to manage requires manually becomes a bit of a gordian knot. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale