title: Why does the Ruby debugger return different values than the code at run time?
body: <p>See this simple Ruby class:</p>
  
  <pre><code>require 'byebug'
  
  class Foo
    def run
      byebug
  
      puts defined?(bar)
      puts bar.inspect
  
      bar = 'local string'
  
      puts defined?(bar)
      puts bar.inspect
    end
  
    def bar
      'string from method'
    end
  end
  
  Foo.new.run
  </code></pre>
  
  <p>When running this class the following behavior can be observed in the debugger's console:</p>
  
  <pre><code>    $ ruby byebug.rb
  
      [2, 11] in /../test.rb
          2:
          3: class Foo
          4:   def run
          5:     byebug
          6:
      =&gt;  7:     puts defined?(bar)
          8:     puts bar.inspect
          9:
         10:     bar = 'local string'
         11:
  </code></pre>
  
  <p>At the breakpoint the debugger returns the following values:</p>
  
  <pre><code>    (byebug) defined?(bar)
      "local-variable"
      (byebug) bar.inspect
      "nil"
  </code></pre>
  
  <p>Note that - although the debugger's breakpoint is in line <code>#5</code> - it already knows that there will be a local variable <code>bar</code> defined in line <code>#10</code> that will shadow the method <code>bar</code> and the debugger is actually not able anymore to call the <code>bar</code> method. What is doesn't know at this point is that the string <code>'local string'</code> will be assign to <code>bar</code>. The debugger returns <code>nil</code> for <code>bar</code>.</p>
  
  <p>Let's continue with the original code in the Ruby file and look at its output:</p>
  
  <pre><code>    (byebug) continue
      method
      "string from method"
      local-variable
      "local string"
  </code></pre>
  
  <p>At run time in line <code>#7</code> Ruby still knowns that <code>bar</code> is indeed a method and it is still able to call it in line <code>#8</code>. Then l ine <code>#10</code> actually defines the local variable that shadows the method with the same name and tTherefore Ruby returns like expected in line <code>#12</code> and <code>#13</code>.</p>
  
  <p>Questions: Why does the debugger return different values than the original code? It seems like it is able to look into the future. Is this considered a feature or a bug? Is this behavior documented?</p>