title: Ruby uninitialized constant error when loading all files in a directory
body: <p>I am trying to load all of the ruby files in a directory from a Ruby file using this code:</p>
  
  <pre><code>Dir["#{File.dirname(__FILE__)}/pages/*_page.rb"].each { |r| load r }
  </code></pre>
  
  <p>However, in this directory I have a Class Bar which inherits from Class Foo.</p>
  
  <pre><code>Class Bar &lt; Foo
  </code></pre>
  
  <p>When I run my program, I get an error:  uninitialized constant Foo (NameError).</p>
  
  <p>I think this is because it is trying to load the Bar class, but has not yet loaded the Foo class.</p>
  
  <p>I have tried explicitly requiring Foo inside of Bar, but then I will get warnings as Foo will have been loaded twice.</p>
  
  <p>How can I load all the files in a directory, in such a way that it will require any needed files automatically.</p>