<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="Object" super="" type="class" ref="xref-000001">
    <subclasses>Array, Binding, Continuation,
    Data, Dir, Exception, FalseClass, File::Stat, Hash, IO,
    MatchingData, Method, Module, NilClass, Numeric, Proc, Range,
    Regexp, String, Struct, Symbol, Thread, Time, TrueClass</subclasses>
<p/>
  <classname>Object</classname> is the parent class of all classes in Ruby. Its methods
  are therefore available to all objects unless explicitly
  overridden.
<p/>
  <classname>Object</classname> mixes in the <modulename>Kernel</modulename> module, making the built-in
  kernel functions globally accessible. Although the instance methods
  of <classname>Object</classname> are defined by the <modulename>Kernel</modulename> module, we have chosen
  to document them here for clarity.
<p/>
  In the descriptions that follow, the
  parameter <obj>aSymbol</obj> refers to a symbol, which is either a
  quoted string or a <classname>Symbol</classname> (such as <tt>:name</tt>).
<p/>
  <methods type="instance">
        <method name="==" ref="_eq_eq">
      <callseq>
        <obj>obj</obj> == <obj>anObject</obj>
        <returns><const>true</const> or <const>false</const></returns>
      </callseq>
      <desc>
<p/>
      Equality---At the <classname>Object</classname> level, <tt>==</tt> returns <const>true</const> only if
      <obj>obj</obj> and <obj>anObject</obj> are the same object. Typically, this
      method is overridden in descendent classes to provide
      class-specific meaning.
<p/>
      </desc>
    </method>
<p/>
        <method name="===" ref="_eq_eq_eq">
      <callseq>
        <obj>obj</obj> === <obj>anObject</obj>
        <returns><const>true</const> or <const>false</const></returns>
      </callseq>
      <desc>
<p/>
      Case Equality---A synonym for <cim><file>object</file><front>Object</front><back>==</back><mref>_eq_eq</mref></cim>, but typically overridden by
      descendents to provide meaningful semantics in <tt>case</tt>
      statements.
<p/>
      </desc>
    </method>
<p/>
        <method name="=~" ref="_eq_sd">
      <callseq>
        <obj>obj</obj> =~ <obj>anObject</obj>
        <returns><const>false</const></returns>
      </callseq>
      <desc>
<p/>
      Pattern Match---Overridden by descendents (notably <classname>Regexp</classname>
      and <classname>String</classname>) to provide meaningful
      pattern-match semantics.
<p/>
      </desc>
    </method>
<p/>
        <method name="__id__" ref="__id__">
      <callseq>
        <obj>obj</obj>.__id__
        <returns><obj>aFixnum</obj></returns>
      </callseq>
      <desc>
<p/>
      Synonym for <cim><file>object</file><front>Object</front><back>id</back><mref>id</mref></cim>.
<p/>
      </desc>
    </method>
<p/>
        <method name="__send__" ref="__send__">
      <callseq>
        <obj>obj</obj>.__send__(
        <obj>aSymbol</obj> <optn>, <obj>args</obj></optn> ) <returns><obj>anObject</obj></returns>
      </callseq>
      <desc>
<p/>
      Synonym for <cim><file>object</file><front>Object</front><back>send</back><mref>send</mref></cim>.
<p/>
      </desc>
    </method>
<p/>
        <method name="class" ref="class">
      <callseq>
        <obj>obj</obj>.class <returns><obj>aClass</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns the class of <obj>obj</obj> (synonym for <cim><file>object</file><front>Object</front><back>type</back><mref>type</mref></cim>). 
<p/>
      </desc>
    </method>
<p/>
        <method name="clone" ref="clone">
      <callseq>
        <obj>obj</obj>.clone <returns><obj>anObject</obj></returns>
      </callseq>
      <desc>
<p/>
      Produces a shallow copy of <obj>obj</obj>---the instance variables of <obj>obj</obj>
      are copied, but not the objects they reference. 
      Copies the frozen and tainted state of <obj>obj</obj>. See also the
      discussion under <cim><file>object</file><front>Object</front><back>dup</back><mref>dup</mref></cim>.
<p/>
<codefragment>
<fullcode><![CDATA[         class Klass
            attr_accessor :str
         end
         s1 = Klass.new
         s1.str = "Hello"
         s2 = s1.clone
         s2.str[1,4] = "i"
         s1.inspect
         s2.inspect
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>class<nbsp/>Klass</tt></td>
</tr>
<tr>
<td colspan="3"><tt><nbsp/><nbsp/><nbsp/>attr_accessor<nbsp/>:str</tt></td>
</tr>
<tr>
<td colspan="3"><tt>end</tt></td>
</tr>
<tr>
  <td><tt>s1<nbsp/>=<nbsp/>Klass.new</tt></td>
  <td>&#187;</td>
  <td><tt>#&lt;Klass:0x401b5478&gt;</tt></td>
</tr>
<tr>
  <td><tt>s1.str<nbsp/>=<nbsp/>"Hello"</tt></td>
  <td>&#187;</td>
  <td><tt>"Hello"</tt></td>
</tr>
<tr>
  <td><tt>s2<nbsp/>=<nbsp/>s1.clone</tt></td>
  <td>&#187;</td>
  <td><tt>#&lt;Klass:0x401b5194<nbsp/>@str="Hello"&gt;</tt></td>
</tr>
<tr>
  <td><tt>s2.str[1,4]<nbsp/>=<nbsp/>"i"</tt></td>
  <td>&#187;</td>
  <td><tt>"i"</tt></td>
</tr>
<tr>
  <td><tt>s1.inspect</tt></td>
  <td>&#187;</td>
  <td><tt>"#&lt;Klass:0x401b5478<nbsp/>@str=\"Hi\"&gt;"</tt></td>
</tr>
<tr>
  <td><tt>s2.inspect</tt></td>
  <td>&#187;</td>
  <td><tt>"#&lt;Klass:0x401b5194<nbsp/>@str=\"Hi\"&gt;"</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="display" ref="display">
      <callseq>
        <obj>obj</obj>.display( <obj>port</obj>=<var>$&gt;</var> )
        <returns><tt>nil</tt></returns>
      </callseq>
      <desc>
<p/>
      Prints <obj>obj</obj> on the given port (default <var>$&gt;</var>). Equivalent 
      to:
<p/>
<codefragment>
<alltt><fullcode><![CDATA[        def display(port=$>)
          port.write self
        end
]]></fullcode>
def<nbsp/>display(port=$&gt;)
<nbsp/><nbsp/>port.write<nbsp/>self
end
</alltt>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="dup" ref="dup">
      <callseq>
        <obj>obj</obj>.dup <returns><obj>anObject</obj></returns>
      </callseq>
      <desc>
<p/>
      Produces a shallow copy      
      of <obj>obj</obj>---the instance variables of <obj>obj</obj>
      are copied, but not the objects they reference. <meth>dup</meth>
      copies the tainted state of <obj>obj</obj>. See also the
      discussion under <cim><file>object</file><front>Object</front><back>clone</back><mref>clone</mref></cim>.
      In general,
      <meth>clone</meth> and <meth>dup</meth> may have different semantics in
      descendent classes. While <meth>clone</meth> is used to duplicate an 
      object, including its internal state, <meth>dup</meth> typically
      uses the class of the descendent object to create the new instance.
<p/>
      </desc>
    </method>
<p/>
        <method name="eql?" ref="eql_qm">
      <callseq>
        <obj>obj</obj>.eql?( <obj>anObject</obj> )
        <returns><const>true</const> or <const>false</const></returns>
      </callseq>
      <desc>
<p/>
      Returns <const>true</const> if <obj>obj</obj> and <obj>anObject</obj> have the
      same value. Used by <classname>Hash</classname> to test
      members for equality. For objects of class <classname>Object</classname>,
      <meth>eql?</meth> is synonymous with <meth>==</meth>. Subclasses
      normally continue this tradition, but there are
      exceptions. <classname>Numeric</classname> types, for example, perform type
      conversion across <meth>==</meth>, but not across <meth>eql?</meth>, so:
<p/>
<codefragment>
<fullcode><![CDATA[        1 == 1.0
        1.eql? 1.0
]]></fullcode><rubycode>
<tr>
  <td><tt>1<nbsp/>==<nbsp/>1.0</tt></td>
  <td>&#187;</td>
  <td><tt>true</tt></td>
</tr>
<tr>
  <td><tt>1.eql?<nbsp/>1.0</tt></td>
  <td>&#187;</td>
  <td><tt>false</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="equal?" ref="equal_qm">
      <callseq>
        <obj>obj</obj>.equal?( <obj>anObject</obj> )
        <returns><const>true</const> or <const>false</const></returns>
      </callseq>
      <desc>
<p/>
      Returns <const>true</const> if <obj>obj</obj> and <obj>anObject</obj> have the
      same object ID. This method should
      not be overridden by subclasses.
<p/>
<codefragment>
<fullcode><![CDATA[         a = [ 'cat', 'dog' ]
         b = [ 'cat', 'dog' ]
         a == b
         a.id == b.id
         a.eql?(b)
         a.equal?(b)
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>a<nbsp/>=<nbsp/>[<nbsp/>'cat',<nbsp/>'dog'<nbsp/>]</tt></td>
</tr>
<tr>
<td colspan="3"><tt>b<nbsp/>=<nbsp/>[<nbsp/>'cat',<nbsp/>'dog'<nbsp/>]</tt></td>
</tr>
<tr>
  <td><tt>a<nbsp/>==<nbsp/>b</tt></td>
  <td>&#187;</td>
  <td><tt>true</tt></td>
</tr>
<tr>
  <td><tt>a.id<nbsp/>==<nbsp/>b.id</tt></td>
  <td>&#187;</td>
  <td><tt>false</tt></td>
</tr>
<tr>
  <td><tt>a.eql?(b)</tt></td>
  <td>&#187;</td>
  <td><tt>true</tt></td>
</tr>
<tr>
  <td><tt>a.equal?(b)</tt></td>
  <td>&#187;</td>
  <td><tt>false</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="extend" ref="extend">
      <callseq>
                <obj>obj</obj>.extend( <optn><obj>aModule</obj></optn> )
        <returns><obj>obj</obj></returns>
      </callseq>
      <desc>
<p/>
      Adds to <obj>obj</obj> the instance methods from each module given as a parameter.
<p/>
<codefragment>
<fullcode><![CDATA[         module Mod
           def hello
             "Hello from Mod.\n"
           end
         end
         
         class Klass
           def hello
             "Hello from Klass.\n"
           end           
         end
         
         k = Klass.new
         k.hello
         k.extend(Mod)
         k.hello
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>module<nbsp/>Mod</tt></td>
</tr>
<tr>
<td colspan="3"><tt><nbsp/><nbsp/>def<nbsp/>hello</tt></td>
</tr>
<tr>
<td colspan="3"><tt><nbsp/><nbsp/><nbsp/><nbsp/>"Hello<nbsp/>from<nbsp/>Mod.\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></tt></td>
</tr>
<tr>
<td colspan="3"><tt>class<nbsp/>Klass</tt></td>
</tr>
<tr>
<td colspan="3"><tt><nbsp/><nbsp/>def<nbsp/>hello</tt></td>
</tr>
<tr>
<td colspan="3"><tt><nbsp/><nbsp/><nbsp/><nbsp/>"Hello<nbsp/>from<nbsp/>Klass.\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></tt></td>
</tr>
<tr>
<td colspan="3"><tt>k<nbsp/>=<nbsp/>Klass.new</tt></td>
</tr>
<tr>
  <td><tt>k.hello</tt></td>
  <td>&#187;</td>
  <td><tt>"Hello<nbsp/>from<nbsp/>Klass.\n"</tt></td>
</tr>
<tr>
  <td><tt>k.extend(Mod)</tt></td>
  <td>&#187;</td>
  <td><tt>#&lt;Klass:0x401b598c&gt;</tt></td>
</tr>
<tr>
  <td><tt>k.hello</tt></td>
  <td>&#187;</td>
  <td><tt>"Hello<nbsp/>from<nbsp/>Mod.\n"</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="freeze" ref="freeze">
      <callseq>
        <obj>obj</obj>.freeze <returns><obj>obj</obj></returns>
      </callseq>
      <desc>
<p/>
      Prevents further modifications to <obj>obj</obj>. A <exception>TypeError</exception>
      will be raised if modification is attempted. There is no way to
      unfreeze a frozen object.
      See also <cim><file>object</file><front>Object</front><back>frozen?</back><mref>frozen_qm</mref></cim>.
<p/>
<codefragment>
<alltt><fullcode><![CDATA[        a = [ "a", "b", "c" ]
        a.freeze
        a << "z"
]]></fullcode>
a<nbsp/>=<nbsp/>[<nbsp/>"a",<nbsp/>"b",<nbsp/>"c"<nbsp/>]
a.freeze
a<nbsp/>&lt;&lt;<nbsp/>"z"
</alltt>
</codefragment>
<em>produces:</em>
<codefragment><alltt>
prog.rb:3:in<nbsp/>`&lt;&lt;':<nbsp/>can't<nbsp/>modify<nbsp/>frozen<nbsp/>array<nbsp/>(TypeError)
	from<nbsp/>prog.rb:3
</alltt>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="frozen?" ref="frozen_qm">
      <callseq>
        <obj>obj</obj>.frozen? 
        <returns><const>true</const> or <const>false</const></returns>
      </callseq>
      <desc>
<p/>
      Returns the freeze status of <obj>obj</obj>.
<p/>
<codefragment>
<fullcode><![CDATA[        a = [ "a", "b", "c" ]
        a.freeze
        a.frozen?
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>a<nbsp/>=<nbsp/>[<nbsp/>"a",<nbsp/>"b",<nbsp/>"c"<nbsp/>]</tt></td>
</tr>
<tr>
  <td><tt>a.freeze</tt></td>
  <td>&#187;</td>
  <td><tt>["a",<nbsp/>"b",<nbsp/>"c"]</tt></td>
</tr>
<tr>
  <td><tt>a.frozen?</tt></td>
  <td>&#187;</td>
  <td><tt>true</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="hash" ref="hash">
      <callseq>
        <obj>obj</obj>.hash <returns><obj>aFixnum</obj></returns>
      </callseq>
      <desc>
<p/>
      Generates a <classname>Fixnum</classname> hash value for this object. This function 
      must have the property that <tt>a.eql?(b)</tt> implies <tt>a.hash == 
        b.hash</tt>. The hash value is used by class <classname>Hash</classname>.
      Any hash value that exceeds the
      capacity of a <classname>Fixnum</classname> will be truncated before being used.
<p/>
      </desc>
    </method>
<p/>
        <method name="id" ref="id">
      <callseq>
        <obj>obj</obj>.id <returns><obj>aFixnum</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns an integer identifier for <obj>obj</obj>. The same number will be 
      returned on all calls to <meth>id</meth> for a given object, and no
      two active objects will share an id. <cim><file>object</file><front>Object</front><back>id</back><mref>id</mref></cim> is a
      different concept from the <tt>:name</tt> notation, which returns the
      symbol id of <tt>name</tt>.
<p/>
      </desc>
    </method>
<p/>
        <method name="inspect" ref="inspect">
      <callseq>
        <obj>obj</obj>.inspect <returns><obj>aString</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns a string containing a human-readable representation of
      <obj>obj</obj>. If not overridden, uses the <tt>to_s</tt> method to generate
      the string.
<p/>
<codefragment>
<fullcode><![CDATA[         [ 1, 2, 3..4, 'five' ].inspect
         Time.new.inspect
]]></fullcode><rubycode>
<tr>
  <td><tt>[<nbsp/>1,<nbsp/>2,<nbsp/>3..4,<nbsp/>'five'<nbsp/>].inspect</tt></td>
  <td>&#187;</td>
  <td><tt>"[1,<nbsp/>2,<nbsp/>3..4,<nbsp/>\"five\"]"</tt></td>
</tr>
<tr>
  <td><tt>Time.new.inspect</tt></td>
  <td>&#187;</td>
  <td><tt>"Sun<nbsp/>Jun<nbsp/>09<nbsp/>00:18:15<nbsp/>CDT<nbsp/>2002"</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="instance_eval" ref="instance_eval">
      <callseq>
                    <obj>obj</obj>.instance_eval(<obj>aString</obj>
                                 <opt>, <obj>file</obj>
                                         <opt><obj>line</obj></opt></opt> )
                                <returns><obj>anObject</obj></returns><br/><obj>obj</obj>.instance_eval <block>{|  | <blockbody>block</blockbody> }</block>
 <returns><obj>anObject</obj></returns>
      </callseq>
      <desc>
<p/>
      Evaluates a string containing Ruby source code, or the given
      block, within the
      context of the receiver (<obj>obj</obj>). In order to set the context, the 
      variable <var>self</var> is set to <obj>obj</obj> while the code is
      executing, giving the code access to <obj>obj</obj>'s instance variables.
      In the version of <meth>instance_eval</meth> that takes a
      <classname>String</classname>, the optional second and third parameters supply a
      filename and starting line number that are used when reporting
      compilation errors.
<p/>
<codefragment>
<fullcode><![CDATA[        class Klass
          def initialize
            @secret = 99
          end
        end
        k = Klass.new
        k.instance_eval { @secret }
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>class<nbsp/>Klass</tt></td>
</tr>
<tr>
<td colspan="3"><tt><nbsp/><nbsp/>def<nbsp/>initialize</tt></td>
</tr>
<tr>
<td colspan="3"><tt><nbsp/><nbsp/><nbsp/><nbsp/>@secret<nbsp/>=<nbsp/>99</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>k<nbsp/>=<nbsp/>Klass.new</tt></td>
</tr>
<tr>
  <td><tt>k.instance_eval<nbsp/>{<nbsp/>@secret<nbsp/>}</tt></td>
  <td>&#187;</td>
  <td><tt>99</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="instance_of?" ref="instance_of_qm">
      <callseq>
        <obj>obj</obj>.instance_of?( <obj>aClass</obj> ) 
        <returns><const>true</const> or <const>false</const></returns>
      </callseq>
      <desc>
<p/>
      Returns <const>true</const> if <obj>obj</obj> is an instance of the 
      given class. See also <cim><file>object</file><front>Object</front><back>kind_of?</back><mref>kind_of_qm</mref></cim>.
<p/>
      </desc>
    </method>
<p/>
        <method name="instance_variables" ref="instance_variables">
      <callseq>
        <obj>obj</obj>.instance_variables
        <returns><obj>anArray</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns an array of instance variable names for the
      receiver.
<p/>
      </desc>
    </method>
<p/>
        <method name="is_a?" ref="is_a_qm">
      <callseq>
        <obj>obj</obj>.is_a?( <obj>aClass</obj> ) 
        <returns><const>true</const> or <const>false</const></returns>
      </callseq>
      <desc>
<p/>
      Synonym for <cim><file>object</file><front>Object</front><back>kind_of?</back><mref>kind_of_qm</mref></cim>.
<p/>
      </desc>
    </method>
<p/>
        <method name="kind_of?" ref="kind_of_qm">
      <callseq>
        <obj>obj</obj>.kind_of?( <obj>aClass</obj> ) 
        <returns><const>true</const> or <const>false</const></returns>
      </callseq>
      <desc>
              Returns <const>true</const> if <obj>aClass</obj> is the class of <obj>obj</obj>, or 
      if <obj>aClass</obj> is one of the superclasses of <obj>obj</obj> or modules included
      in <obj>obj</obj>.
<p/>
<codefragment>
<fullcode><![CDATA[        a = 1
        a.instance_of? Numeric
        a.instance_of? Integer
        a.instance_of? Fixnum
        a.instance_of? Comparable
        a.kind_of? Numeric
        a.kind_of? Integer
        a.kind_of? Fixnum
        a.kind_of? Comparable
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>a<nbsp/>=<nbsp/>1</tt></td>
</tr>
<tr>
  <td><tt>a.instance_of?<nbsp/>Numeric</tt></td>
  <td>&#187;</td>
  <td><tt>false</tt></td>
</tr>
<tr>
  <td><tt>a.instance_of?<nbsp/>Integer</tt></td>
  <td>&#187;</td>
  <td><tt>false</tt></td>
</tr>
<tr>
  <td><tt>a.instance_of?<nbsp/>Fixnum</tt></td>
  <td>&#187;</td>
  <td><tt>true</tt></td>
</tr>
<tr>
  <td><tt>a.instance_of?<nbsp/>Comparable</tt></td>
  <td>&#187;</td>
  <td><tt>false</tt></td>
</tr>
<tr>
  <td><tt>a.kind_of?<nbsp/>Numeric</tt></td>
  <td>&#187;</td>
  <td><tt>true</tt></td>
</tr>
<tr>
  <td><tt>a.kind_of?<nbsp/>Integer</tt></td>
  <td>&#187;</td>
  <td><tt>true</tt></td>
</tr>
<tr>
  <td><tt>a.kind_of?<nbsp/>Fixnum</tt></td>
  <td>&#187;</td>
  <td><tt>true</tt></td>
</tr>
<tr>
  <td><tt>a.kind_of?<nbsp/>Comparable</tt></td>
  <td>&#187;</td>
  <td><tt>true</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="method" ref="method">
      <callseq>
        <obj>obj</obj>.method( <obj>aSymbol</obj> )
        <returns><obj>aMethod</obj></returns>
      </callseq>
      <desc>
<p/>
      Looks up the named method as a receiver in <obj>obj</obj>, returning a
      <classname>Method</classname> object (or raising <exception>NameError</exception>). The <classname>Method</classname> object acts
      as a closure in <obj>obj</obj>'s object instance, so instance variables
      and the value of <const>self</const> remain available.
<p/>
<codefragment>
<fullcode><![CDATA[         class Demo
           def initialize(n)
             @iv = n
           end
           def hello()
             "Hello, @iv = #{@iv}"
           end
         end
         
         k = Demo.new(99)
         m = k.method(:hello)
         m.call
         
         l = Demo.new('Fred')
         m = l.method("hello")
         m.call
]]></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/>@iv<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/>hello()</tt></td>
</tr>
<tr>
<td colspan="3"><tt><nbsp/><nbsp/><nbsp/><nbsp/>"Hello,<nbsp/>@iv<nbsp/>=<nbsp/>#{@iv}"</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>k<nbsp/>=<nbsp/>Demo.new(99)</tt></td>
</tr>
<tr>
<td colspan="3"><tt>m<nbsp/>=<nbsp/>k.method(:hello)</tt></td>
</tr>
<tr>
  <td><tt>m.call</tt></td>
  <td>&#187;</td>
  <td><tt>"Hello,<nbsp/>@iv<nbsp/>=<nbsp/>99"</tt></td>
</tr>
<tr>
<td colspan="3"><tt></tt></td>
</tr>
<tr>
<td colspan="3"><tt>l<nbsp/>=<nbsp/>Demo.new('Fred')</tt></td>
</tr>
<tr>
<td colspan="3"><tt>m<nbsp/>=<nbsp/>l.method("hello")</tt></td>
</tr>
<tr>
  <td><tt>m.call</tt></td>
  <td>&#187;</td>
  <td><tt>"Hello,<nbsp/>@iv<nbsp/>=<nbsp/>Fred"</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="method_missing" ref="method_missing">
      <callseq>
                <obj>obj</obj>.method_missing( <obj>aSymbol</obj> <opt>, <obj>*args</obj></opt> )
        <returns><obj>anObject</obj></returns>
      </callseq>
      <desc>
              Invoked by Ruby when <obj>obj</obj> is sent a message it cannot
      handle. <obj>aSymbol</obj> is the symbol for the method called,
      and <obj>args</obj> are any arguments that were passed to it. The
      example below creates a class <tt>Roman</tt>, which responds to methods
      with names consisting of roman numerals, returning the corresponding
      integer values.
<p/>
<codefragment>
<alltt><fullcode><![CDATA[        class Roman
          def romanToInt(str)
            # ...
!-            case str
!-            when "iv"; return 4
!-            when "xxiii"; return 23
!-            when "mm"; return 2000
!-            else; raise "oops #{str}"
!-            end
          end         
          def method_missing(methId)
            str = methId.id2name
            romanToInt(str)
          end
        end
]]></fullcode>
class<nbsp/>Roman
<nbsp/><nbsp/>def<nbsp/>romanToInt(str)
<nbsp/><nbsp/><nbsp/><nbsp/>#<nbsp/>...
<nbsp/><nbsp/>end
<nbsp/><nbsp/>def<nbsp/>method_missing(methId)
<nbsp/><nbsp/><nbsp/><nbsp/>str<nbsp/>=<nbsp/>methId.id2name
<nbsp/><nbsp/><nbsp/><nbsp/>romanToInt(str)
<nbsp/><nbsp/>end
end
</alltt>
</codefragment>
<p/>
<codefragment>
<fullcode><![CDATA[!-        class Roman
!-          def romanToInt(str)
!-            # ...
!-            case str
!-            when "iv"; return 4
!-            when "xxiii"; return 23
!-            when "mm"; return 2000
!-            else; raise "oops #{str}"
!-            end
!-          end         
!-          def method_missing(methId)
!-            str = methId.id2name
!-            romanToInt(str)
!-          end
!-        end
        r = Roman.new
        r.iv
        r.xxiii
        r.mm
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>r<nbsp/>=<nbsp/>Roman.new</tt></td>
</tr>
<tr>
  <td><tt>r.iv</tt></td>
  <td>&#187;</td>
  <td><tt>4</tt></td>
</tr>
<tr>
  <td><tt>r.xxiii</tt></td>
  <td>&#187;</td>
  <td><tt>23</tt></td>
</tr>
<tr>
  <td><tt>r.mm</tt></td>
  <td>&#187;</td>
  <td><tt>2000</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="methods" ref="methods">
      <callseq>
        <obj>obj</obj>.methods <returns><obj>anArray</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns a list of the names of methods publicly accessible in
      <obj>obj</obj>. This will include all the methods accessible in <obj>obj</obj>'s
      ancestors. 
<p/>
<codefragment>
<fullcode><![CDATA[         class Klass
           def kMethod()
           end
         end
         k = Klass.new
         k.methods[0..9]
         k.methods.length
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>class<nbsp/>Klass</tt></td>
</tr>
<tr>
<td colspan="3"><tt><nbsp/><nbsp/>def<nbsp/>kMethod()</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>k<nbsp/>=<nbsp/>Klass.new</tt></td>
</tr>
<tr>
  <td><tt>k.methods[0..9]</tt></td>
  <td>&#187;</td>
  <td><tt>["kMethod",<nbsp/>"dup",<nbsp/>"eql?",<nbsp/>"protected_methods",<nbsp/>"==",<nbsp/>"frozen?",<nbsp/>"===",<nbsp/>"respond_to?",<nbsp/>"class",<nbsp/>"kind_of?"]</tt></td>
</tr>
<tr>
  <td><tt>k.methods.length</tt></td>
  <td>&#187;</td>
  <td><tt>38</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="nil?" ref="nil_qm">
      <callseq>
        <obj>obj</obj>.nil? <returns><const>true</const> or <const>false</const></returns>
      </callseq>
      <desc>
<p/>
      All objects except <tt>nil</tt> return <const>false</const>.
<p/>
      </desc>
    </method>
<p/>
        <method name="private_methods" ref="private_methods">
      <callseq>
        <obj>obj</obj>.private_methods
        <returns><obj>anArray</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns a list of private methods accessible within <obj>obj</obj>. This
      will include the private methods in <obj>obj</obj>'s ancestors, along
      with any mixed-in module functions.
<p/>
      </desc>
    </method>
<p/>
        <method name="protected_methods" ref="protected_methods">
      <callseq>
        <obj>obj</obj>.protected_methods
        <returns><obj>anArray</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns the list of protected methods accessible to <obj>obj</obj>.
<p/>
      </desc>
    </method>
<p/>
        <method name="public_methods" ref="public_methods">
      <callseq>
                <obj>obj</obj>.public_methods <returns><obj>anArray</obj></returns>
      </callseq>
      <desc>
<p/>
      Synonym for <cim><file>object</file><front>Object</front><back>methods</back><mref>methods</mref></cim>.
<p/>
      </desc>
    </method>
<p/>
        <method name="respond_to?" ref="respond_to_qm">
      <callseq>
                <obj>obj</obj>.respond_to?( <obj>aSymbol</obj>,
                            <obj>includePriv</obj>=<const>false</const> )
            <returns><const>true</const> or <const>false</const></returns>
      </callseq>
      <desc>
<p/>
      Returns <const>true</const> if <obj>obj</obj> responds to the given
      method. Private methods are included in the search only if the
      optional second parameter evaluates to <const>true</const>.
<p/>
      </desc>
    </method>
<p/>
        <method name="send" ref="send">
      <callseq>
        <obj>obj</obj>.send( <obj>aSymbol</obj>
        <optz>, <obj>args</obj></optz> ) <returns><obj>anObject</obj></returns>
      </callseq>
      <desc>
<p/>
      Invokes the method identified by <obj>aSymbol</obj>, passing it any
      arguments specified. You can use <meth>__send__</meth> if the
      name <meth>send</meth> clashes with an existing method in <obj>obj</obj>.
<p/>
<codefragment>
<fullcode><![CDATA[        class Klass
          def hello(*args)
            "Hello " + args.join(' ')
          end
        end
        k = Klass.new
        k.send :hello, "gentle", "readers"
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>class<nbsp/>Klass</tt></td>
</tr>
<tr>
<td colspan="3"><tt><nbsp/><nbsp/>def<nbsp/>hello(*args)</tt></td>
</tr>
<tr>
<td colspan="3"><tt><nbsp/><nbsp/><nbsp/><nbsp/>"Hello<nbsp/>"<nbsp/>+<nbsp/>args.join('<nbsp/>')</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>k<nbsp/>=<nbsp/>Klass.new</tt></td>
</tr>
<tr>
  <td><tt>k.send<nbsp/>:hello,<nbsp/>"gentle",<nbsp/>"readers"</tt></td>
  <td>&#187;</td>
  <td><tt>"Hello<nbsp/>gentle<nbsp/>readers"</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="singleton_methods" ref="singleton_methods">
      <callseq>
        <obj>obj</obj>.singleton_methods
        <returns><obj>anArray</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns an array of the names of singleton methods for <obj>obj</obj>.
<p/>
<codefragment>
<fullcode><![CDATA[          class Klass
            def Klass.classMethod
            end
          end
          k = Klass.new
          def k.sm()
          end
          Klass.singleton_methods
          k.singleton_methods
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>class<nbsp/>Klass</tt></td>
</tr>
<tr>
<td colspan="3"><tt><nbsp/><nbsp/>def<nbsp/>Klass.classMethod</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>k<nbsp/>=<nbsp/>Klass.new</tt></td>
</tr>
<tr>
<td colspan="3"><tt>def<nbsp/>k.sm()</tt></td>
</tr>
<tr>
<td colspan="3"><tt>end</tt></td>
</tr>
<tr>
  <td><tt>Klass.singleton_methods</tt></td>
  <td>&#187;</td>
  <td><tt>["classMethod"]</tt></td>
</tr>
<tr>
  <td><tt>k.singleton_methods</tt></td>
  <td>&#187;</td>
  <td><tt>["sm"]</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="taint" ref="taint">
      <callseq>
        <obj>obj</obj>.taint <returns><obj>obj</obj></returns>
      </callseq>
      <desc>
<p/>
      Marks <obj>obj</obj> as tainted      
      (see Chapter 20, which begins on page 253).
<p/>
      </desc>
    </method>
<p/>
        <method name="tainted?" ref="tainted_qm">
      <callseq>
        <obj>obj</obj>.tainted? <returns><const>true</const> or <const>false</const></returns>
      </callseq>
      <desc>
<p/>
      Returns <const>true</const> if the object is tainted.
<p/>
      </desc>
    </method>
<p/>
        <method name="to_a" ref="to_a">
      <callseq>
        <obj>obj</obj>.to_a <returns><obj>anArray</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns an array representation of <obj>obj</obj>. For
      objects of class <classname>Object</classname> and others that don't explicitly
      override the method, the return value is an array containing <const>self</const>.
<p/>
<codefragment>
<fullcode><![CDATA[         self.to_a
         "hello".to_a
         Time.new.to_a
]]></fullcode><rubycode>
<tr>
  <td><tt>self.to_a</tt></td>
  <td>&#187;</td>
  <td><tt>[main]</tt></td>
</tr>
<tr>
  <td><tt>"hello".to_a</tt></td>
  <td>&#187;</td>
  <td><tt>["hello"]</tt></td>
</tr>
<tr>
  <td><tt>Time.new.to_a</tt></td>
  <td>&#187;</td>
  <td><tt>[15,<nbsp/>18,<nbsp/>0,<nbsp/>9,<nbsp/>6,<nbsp/>2002,<nbsp/>0,<nbsp/>160,<nbsp/>true,<nbsp/>"CDT"]</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="to_s" ref="to_s">
      <callseq>
        <obj>obj</obj>.to_s <returns><obj>aString</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns a string representing <obj>obj</obj>. The default <meth>to_s</meth>
      prints the object's class and an encoding of the object id. As a
      special case, the top-level object that is the initial execution 
      context of Ruby programs returns ``main.''
<p/>
      </desc>
    </method>
<p/>
        <method name="type" ref="type">
      <callseq>
        <obj>obj</obj>.type <returns><obj>aClass</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns the class of <obj>obj</obj>. 
<p/>
      </desc>
    </method>
<p/>
        <method name="untaint" ref="untaint">
      <callseq>
        <obj>obj</obj>.untaint <returns><obj>obj</obj></returns>
      </callseq>
      <desc>
<p/>
      Removes the taint from <obj>obj</obj>.
<p/>
      </desc>
    </method>
<p/>
  </methods>
<p/>
</class>
</ppdoc>
