title: Ruby scope, returning a Proc from a function
body: <p>Coming from a JavaScript background I've become accustomed to being able to use JavaScript's dynamic scope to encapsulate values in a function. For example:</p>
  
  <pre><code>function Dog( firstname, lastname ) {
  
    this.fullname = firstname + lastname
  
    return {
      say_name: function () {
        return fullname;
      }
    }
  
  }
  </code></pre>
  
  <p>Now in Ruby I'm not so sure something like this would work too well:</p>
  
  <pre><code>class Foo
  
    attr_accessor :bar, :baz
  
    def initialize bar, baz
      @bar = bar
      @baz = baz
    end
  
    def give_me_a_proc
      return Proc.new { @bar + @baz }
    end
  end
  </code></pre>
  
  <p>Can anyone give a quick explanation of how scope works in Ruby? If I call the Proc returned from <code>give_me_a_proc</code>, will it still have access to its define-time scope?</p>
  
  <p>Also do the values become fixed once I define the proc or do any changes made in <code>Foo</code> get carried down to the Proc even after it has been defined? </p>