<ppdoc>
<copyright>
Copyright (c) 2001 by Addison Wesley Longman, Inc. This material may
be distributed only subject to the terms and conditions set forth in
the Open Publication License, v1.0 or later (the latest version is
presently available at http://www.opencontent.org/openpub/).
<p/>
Distribution of substantively modified versions of this document is
prohibited without the explicit permission of the copyright holder.
<p/>
Distribution of the work or derivative of the work in any standard
(paper) book form is prohibited unless prior permission is obtained
from the copyright holder.
</copyright>
<class name="Binding" super="Object" type="class" ref="xref-000001">    Objects of class <classname>Binding</classname> encapsulate the execution context at some
  particular place in the code and retain this context for future use.
  The variables, methods, value of <tt>self</tt>, and possibly an iterator
  block that can be accessed in this context are all retained.
  Binding objects can be created using <mim><file>kernel</file><front>Kernel</front><back>binding</back><mref>binding</mref></mim>, and are
  made available to the callback of <mim><file>kernel</file><front>Kernel</front><back>set_trace_func</back><mref>set_trace_func</mref></mim>.
<p/>
  These binding objects can be passed as the second argument of the
  <mim><file>kernel</file><front>Kernel</front><back>eval</back><mref>eval</mref></mim> method, establishing an environment for the
  evaluation.
<p/>
<codefragment>
<fullcode><![CDATA[  class Demo
    def initialize(n)
      @secret = n
    end
    def getBinding
      return binding()
    end
  end

  k1 = Demo.new(99)
  b1 = k1.getBinding
  k2 = Demo.new(-3)
  b2 = k2.getBinding

  eval("@secret", b1)
  eval("@secret", b2)
  eval("@secret")
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>class<nbsp/>Demo</tt></td>
</tr>
<tr>
<td colspan="3"><tt><nbsp/><nbsp/>def<nbsp/>initialize(n)</tt></td>
</tr>
<tr>
<td colspan="3"><tt><nbsp/><nbsp/><nbsp/><nbsp/>@secret<nbsp/>=<nbsp/>n</tt></td>
</tr>
<tr>
<td colspan="3"><tt><nbsp/><nbsp/>end</tt></td>
</tr>
<tr>
<td colspan="3"><tt><nbsp/><nbsp/>def<nbsp/>getBinding</tt></td>
</tr>
<tr>
<td colspan="3"><tt><nbsp/><nbsp/><nbsp/><nbsp/>return<nbsp/>binding()</tt></td>
</tr>
<tr>
<td colspan="3"><tt><nbsp/><nbsp/>end</tt></td>
</tr>
<tr>
<td colspan="3"><tt>end</tt></td>
</tr>
<tr>
<td colspan="3"><tt></tt></td>
</tr>
<tr>
<td colspan="3"><tt>k1<nbsp/>=<nbsp/>Demo.new(99)</tt></td>
</tr>
<tr>
<td colspan="3"><tt>b1<nbsp/>=<nbsp/>k1.getBinding</tt></td>
</tr>
<tr>
<td colspan="3"><tt>k2<nbsp/>=<nbsp/>Demo.new(-3)</tt></td>
</tr>
<tr>
<td colspan="3"><tt>b2<nbsp/>=<nbsp/>k2.getBinding</tt></td>
</tr>
<tr>
<td colspan="3"><tt></tt></td>
</tr>
<tr>
  <td><tt>eval("@secret",<nbsp/>b1)</tt></td>
  <td>&#187;</td>
  <td><tt>99</tt></td>
</tr>
<tr>
  <td><tt>eval("@secret",<nbsp/>b2)</tt></td>
  <td>&#187;</td>
  <td><tt>-3</tt></td>
</tr>
<tr>
  <td><tt>eval("@secret")</tt></td>
  <td>&#187;</td>
  <td><tt>nil</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
  Binding objects have no class-specific methods.
</class>
</ppdoc>
