title: Class-objects, singleton classes
body: <p>I play with metaprogramming in ruby and I have a question. I have a class:</p>
  
  <pre><code>class Klass
    class &lt;&lt; self
      @x = "yeah"
    end
  end
  b = Klass.new
  a = class &lt;&lt; Klass; self; end
  a.instance_eval "@x"           #=&gt; yeah
  Klass.instance_eval "@x"       #=&gt; nil
  </code></pre>
  
  <p>Why? In variable <code>a</code> I have a singleton class, right? And <code>Klass.instance_eval</code> exec in context of a singleton class:</p>
  
  <pre><code>Klass.instance_eval "def yeah; puts 10; end"
  Klass.yeah                     #=&gt; 10
  </code></pre>
  
  <p>Also, <code>Klass</code> in interpreter points to context of class, yes? And <code>a</code> points to context of a singleton class?
  And which indicates <code>a.class_eval</code> and <code>a.instance_eval</code>? I do:</p>
  
  <pre><code>a.instance_eval "def pops; puts 0; end"
  a.class_eval "def popsx; puts 1; end"
  a.pops                         #=&gt; 0
  a.popsx                        # FAIL
  Klass.pops                     # FAIL
  Klass.popsx                    #=&gt; 1
  b.pops; b.popsx                # DOUBLE FAIL
  </code></pre>
  
  <p>and I do not understand this. Thanks!     </p>