title: Ruby classes, include, and scope
body: <p>How does including a module affect scope? Specifically, in this example:</p>
  
  <pre><code>module ModuleA
    class ClassA
      def initialize
        puts "test passed"
      end
    end
  end
  
  module ModuleB
    include ModuleA
  
    # test 1
    C = ClassA.new
  
    class ClassB
      def initialize
        c = ClassA.new
      end
    end
  end
  
  # test 2 and 3 fail without this
  #include ModuleB
  
  module ModuleC
    # this doesn't help
    include ModuleB
  
    # test 2
    ClassB.new
  
    # test 3
    ModuleB::ClassB.new
  end
  </code></pre>
  
  <p><strong>test 1</strong> works fine, but <strong>test 2</strong> and <strong>test 3</strong> fail without the commented-out <code>import ModuleB</code>.</p>
  
  <ul>
  <li>Why is <code>ClassA</code> in scope inside of <code>ModuleB</code> (test 1) but not in <code>ClassB</code>?</li>
  <li>Why does the <code>import ModuleB</code> bring <code>ClassA</code> into scope in <code>ClassB</code>?</li>
  </ul>