<ppdoc>
<copyright>
    Copyright (c) 2001 by Addison Wesley Longman.  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/).
</copyright>
<class name="Symbol" super="Object" type="class" ref="xref-000001">
<p/>
  A <classname>Symbol</classname> object represents a Ruby name and is generated
  automatically using the <tt>:name</tt> literal syntax. The same <classname>Symbol</classname>
  object will be created for a given name string for the duration of a
  program's execution, regardless of the context or meaning of that
  name. Thus if <tt>Fred</tt> is a constant in one context, a method in
  another, and a class in a third, the <classname>Symbol</classname> <tt>:Fred</tt> will be
  the same object in all three contexts.
<p/>
<codefragment>
<fullcode><![CDATA[    module One
      class Fred
      end
      $f1 = :Fred
    end
    module Two
      Fred = 1
      $f2 = :Fred
    end
    def Fred()
    end
    $f3 = :Fred
    $f1.id
    $f2.id
    $f3.id
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>module<nbsp/>One</tt></td>
</tr>
<tr>
<td colspan="3"><tt><nbsp/><nbsp/>class<nbsp/>Fred</tt></td>
</tr>
<tr>
<td colspan="3"><tt><nbsp/><nbsp/>end</tt></td>
</tr>
<tr>
<td colspan="3"><tt><nbsp/><nbsp/>$f1<nbsp/>=<nbsp/>:Fred</tt></td>
</tr>
<tr>
<td colspan="3"><tt>end</tt></td>
</tr>
<tr>
<td colspan="3"><tt>module<nbsp/>Two</tt></td>
</tr>
<tr>
<td colspan="3"><tt><nbsp/><nbsp/>Fred<nbsp/>=<nbsp/>1</tt></td>
</tr>
<tr>
<td colspan="3"><tt><nbsp/><nbsp/>$f2<nbsp/>=<nbsp/>:Fred</tt></td>
</tr>
<tr>
<td colspan="3"><tt>end</tt></td>
</tr>
<tr>
<td colspan="3"><tt>def<nbsp/>Fred()</tt></td>
</tr>
<tr>
<td colspan="3"><tt>end</tt></td>
</tr>
<tr>
<td colspan="3"><tt>$f3<nbsp/>=<nbsp/>:Fred</tt></td>
</tr>
<tr>
  <td><tt>$f1.id</tt></td>
  <td>&#187;</td>
  <td><tt>2299150</tt></td>
</tr>
<tr>
  <td><tt>$f2.id</tt></td>
  <td>&#187;</td>
  <td><tt>2299150</tt></td>
</tr>
<tr>
  <td><tt>$f3.id</tt></td>
  <td>&#187;</td>
  <td><tt>2299150</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
  <methods type="instance">
        <method name="id2name" ref="id2name">
      <callseq>
        <obj>sym</obj>.id2name <returns><obj>aString</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns the name corresponding to <obj>sym</obj>.
<p/>
<codefragment>
<fullcode><![CDATA[        :fred.id2name
]]></fullcode><rubycode>
<tr>
  <td><tt>:fred.id2name</tt></td>
  <td>&#187;</td>
  <td><tt>"fred"</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="inspect" ref="inspect">
      <callseq>
        <obj>sym</obj>.inspect <returns><obj>aString</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns the representation of <obj>sym</obj> as a symbol literal.
<p/>
<codefragment>
<fullcode><![CDATA[        :fred.inspect
]]></fullcode><rubycode>
<tr>
  <td><tt>:fred.inspect</tt></td>
  <td>&#187;</td>
  <td><tt>":fred"</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="to_i" ref="to_i">
      <callseq>
        <obj>sym</obj>.to_i  <returns><obj>aFixnum</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns an integer that is unique for each symbol within a
      particular execution of a program.
<p/>
      </desc>
    </method>
<p/>
        <method name="to_s" ref="to_s">
      <callseq>
        <obj>sym</obj>.to_s <returns><obj>aString</obj></returns>
      </callseq>
      <desc>
<p/>
      Synonym for <cim><file>symbol</file><front>Symbol</front><back>id2name</back><mref>id2name</mref></cim>.
<p/>
      </desc>
    </method>
<p/>
  </methods>
<p/>
</class>
</ppdoc>
