title: Why instance_exec and class_exec have this different behavier?
body: <p>I found the following code execerpt from the documentation of <code>instance_exec</code></p>
  
  <pre><code>  class KlassWithSecret
      def initialize
        @secret = 99
      end
    end
    k = KlassWithSecret.new
    k.instance_exec(5) {|x| @secret+x }   #=&gt; 104
  </code></pre>
  
  <p>My understanding of why the instance_exec does is in the following diagram, it add the @secret + 5 in its singleton class</p>
  
  <pre><code>  +-----------------------+
    |   singleton class do  |
    |     def method1       |
    |     ...               |
    |     end               |
    |     ...               |
    |     @secret + 5       |
    |   end                 |
    |                       |
    |                       |
    +-----------+-----------+
                |
      +---------+-------+
      |  instance k     |
      |   @secret       |
      |                 |
      +-----------------+
  </code></pre>
  
  <p>So I came up with the code using class_exec to get the same result</p>
  
  <pre><code>k.singleton_class.class_exec(5) {|x| @secret + x}
  </code></pre>
  
  <p>It give me a @secret is nil error, I want to know why it is and what's wrong with my understanding</p>
  
  <p>update:</p>
  
  <p>I've noticed that k.instance_exec {binding} and k.singleton_class.class_exec {binding} have the different binding object, so they must be differnet. I still want to know how they works under the hood</p>