<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="Method" super="Object" type="class" ref="xref-000001">
    Method objects are created by <cim><file>object</file><front>Object</front><back>method</back><mref>method</mref></cim>, and are associated 
  with a particular object (not just with a class). They may be used
  to invoke the method within the object, and as a block associated with
  an iterator.
<p/>
<codefragment>
<fullcode><![CDATA[     class Thing
       def square(n)
         n*n
       end
     end
     aThing  = Thing.new
     aMethod = aThing.method("square")

     aMethod.call(9)
     [ 1, 2, 3 ].collect(&aMethod)
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>class<nbsp/>Thing</tt></td>
</tr>
<tr>
<td colspan="3"><tt><nbsp/><nbsp/>def<nbsp/>square(n)</tt></td>
</tr>
<tr>
<td colspan="3"><tt><nbsp/><nbsp/><nbsp/><nbsp/>n*n</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>aThing<nbsp/><nbsp/>=<nbsp/>Thing.new</tt></td>
</tr>
<tr>
<td colspan="3"><tt>aMethod<nbsp/>=<nbsp/>aThing.method("square")</tt></td>
</tr>
<tr>
<td colspan="3"><tt></tt></td>
</tr>
<tr>
  <td><tt>aMethod.call(9)</tt></td>
  <td>&#187;</td>
  <td><tt>81</tt></td>
</tr>
<tr>
  <td><tt>[<nbsp/>1,<nbsp/>2,<nbsp/>3<nbsp/>].collect(&amp;aMethod)</tt></td>
  <td>&#187;</td>
  <td><tt>[1,<nbsp/>4,<nbsp/>9]</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
  <methods type="instance">
        <method name="[ ]" ref="_ob_cb">
      <callseq>
        <obj>meth</obj>[ <optz><obj>args</obj></optz> ]
        <returns><obj>anObject</obj></returns>
      </callseq>
      <desc>
<p/>
      Synonym for <tt>Method.call</tt>.
<p/>
      </desc>
    </method>
<p/>
        <method name="arity" ref="arity">
      <callseq>
        <obj>meth</obj>.arity <returns><obj>aFixnum</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns an indication of the number of arguments accepted by a method.
      Returns a nonnegative integer for methods that take a fixed number
      of arguments.  For Ruby methods that take a variable number of 
      arguments, returns -n-1, where n is the number of required
      arguments. For methods written in C, returns -1 if the call
      takes a variable number of arguments.
<p/>
      </desc>
    </method>
<p/>
        <method name="call" ref="call">
      <callseq>
        <obj>meth</obj>.call( <optz><obj>args</obj></optz> )
        <returns><obj>anObject</obj></returns>
      </callseq>
      <desc>
<p/>
      Invokes the <obj>meth</obj> with the specified
      arguments, returning the method's return value.
<p/>
<codefragment>
<fullcode><![CDATA[        m = 12.method("+")
        m.call(3)
        m.call(20)
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>m<nbsp/>=<nbsp/>12.method("+")</tt></td>
</tr>
<tr>
  <td><tt>m.call(3)</tt></td>
  <td>&#187;</td>
  <td><tt>15</tt></td>
</tr>
<tr>
  <td><tt>m.call(20)</tt></td>
  <td>&#187;</td>
  <td><tt>32</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="to_proc" ref="to_proc">
      <callseq>
        <obj>meth</obj>.to_proc <returns><obj>aProc</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns a <classname>Proc</classname> object corresponding to this method.
<p/>
      </desc>
    </method>
<p/>
  </methods>
<p/>
</class>
</ppdoc>
