title: Accessing Ruby Class Variables with class_eval and instance_eval
body: <p>I have the following:</p>
  
  <pre><code>class Test
      @@a = 10
  
      def show_a()
          puts "a: #{@@a}"
      end
  
      class &lt;&lt; self
        @@b = '40'
  
        def show_b
          puts "b: #{@@b}"
      end
    end
  end
  </code></pre>
  
  <p>Why does following work:</p>
  
  <pre><code>Test.instance_eval{show_b}
  b: 40
  =&gt; nil
  </code></pre>
  
  <p>But I can't access <code>@@b</code> directly?</p>
  
  <pre><code>Test.instance_eval{ @@b }
  NameError: uninitialized class variable @@b in Object
  </code></pre>
  
  <p>Likewise, the following works</p>
  
  <pre><code>t = Test.new
  t.instance_eval{show_a}
  a: 10
  =&gt; nil
  </code></pre>
  
  <p>but the following fails</p>
  
  <pre><code>t.instance_eval{ @@a }
  NameError: uninitialized class variable @@a in Object
  </code></pre>
  
  <p>I don't understand why I can't access the Class Variables directly from the <code>instance_eval</code> blocks.</p>