<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="Hash" super="Object" type="class" ref="xref-000001">    
<p/>
  A <classname>Hash</classname> is a collection of key-value pairs.  It is similar to
  an <classname>Array</classname>, except that indexing is done via arbitrary keys of any
  object type, not an integer index.  The order in which you traverse a 
  hash by either key or value may seem arbitrary, and will generally not be
  in the insertion order. 
<p/>
  Hashes have a <em>default value</em> that is returned when accessing
  keys that do not exist in the hash.  By default, that value is
  <tt>nil</tt>.
  <mixins>
    <mixin name="Enumerable">
   collect, detect, each_with_index, entries, find, find_all, grep,
   include?, map, max, member?, min, reject, select, sort, to_a</mixin>
  </mixins>
<p/>
  <methods type="class">
<p/>
        <method name="[ ]" ref="_ob_cb">
      <callseq>
         Hash[ <optz><obj>key</obj> =&gt; <obj>value</obj></optz> ]
        <returns><obj>aHash</obj></returns>
      </callseq>
      <desc>
<p/>
      Creates a new hash populated with the given objects. Equivalent
      to the literal <tt>{<nbsp/><obj>key</obj>, <obj>value</obj>, ...<nbsp/>}</tt>.
      Keys and values occur in pairs, so there must be an
      even number of arguments.
<p/>
<codefragment>
<fullcode><![CDATA[        Hash["a", 100, "b", 200]
        Hash["a" => 100, "b" => 200]
        { "a" => 100, "b" => 200 }
]]></fullcode><rubycode>
<tr>
  <td><tt>Hash["a",<nbsp/>100,<nbsp/>"b",<nbsp/>200]</tt></td>
  <td>&#187;</td>
  <td><tt>{"a"=&gt;100,<nbsp/>"b"=&gt;200}</tt></td>
</tr>
<tr>
  <td><tt>Hash["a"<nbsp/>=&gt;<nbsp/>100,<nbsp/>"b"<nbsp/>=&gt;<nbsp/>200]</tt></td>
  <td>&#187;</td>
  <td><tt>{"a"=&gt;100,<nbsp/>"b"=&gt;200}</tt></td>
</tr>
<tr>
  <td><tt>{<nbsp/>"a"<nbsp/>=&gt;<nbsp/>100,<nbsp/>"b"<nbsp/>=&gt;<nbsp/>200<nbsp/>}</tt></td>
  <td>&#187;</td>
  <td><tt>{"a"=&gt;100,<nbsp/>"b"=&gt;200}</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="new" ref="new">
      <callseq>
        Hash.new( <obj>anObject</obj>=<tt>nil</tt> )
          <returns><obj>aHash</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns a new, empty hash.  If <obj>anObject</obj> is
      specified, it will be used as the <em>default value</em>.
<p/>
<codefragment>
<fullcode><![CDATA[        h = Hash.new("Go Fish")
        h["a"] = 100
        h["b"] = 200
        h["a"]
        h["c"]
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>h<nbsp/>=<nbsp/>Hash.new("Go<nbsp/>Fish")</tt></td>
</tr>
<tr>
<td colspan="3"><tt>h["a"]<nbsp/>=<nbsp/>100</tt></td>
</tr>
<tr>
<td colspan="3"><tt>h["b"]<nbsp/>=<nbsp/>200</tt></td>
</tr>
<tr>
  <td><tt>h["a"]</tt></td>
  <td>&#187;</td>
  <td><tt>100</tt></td>
</tr>
<tr>
  <td><tt>h["c"]</tt></td>
  <td>&#187;</td>
  <td><tt>"Go<nbsp/>Fish"</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
  </methods>
<p/>
  <methods type="instance">
<p/>
         <method name="==" ref="_eq_eq">
      <callseq>
        <obj>hsh</obj> == <obj>anOtherHash</obj>
         <returns><const>true</const> or <const>false</const></returns>
      </callseq>
      <desc>
<p/>
       Equality---Two hashes are equal if they each contain the same number
       of keys and if each key-value pair is equal to (according to
       <cim><file>object</file><front>Object</front><back>==</back><mref>_eq_eq</mref></cim>) the corresponding elements in the other hash.
<p/>
<codefragment>
<fullcode><![CDATA[         h1 = { "a" => 1, "c" => 2 } 
         h2 = { "a" => 1, "c" => 2, 7 => 35 }
         h3 = { "a" => 1, "c" => 2, 7 => 35 }
         h4 = { "a" => 1, "d" => 2, "f" => 35 }
         h1 == h2
         h2 == h3
         h3 == h4
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>h1<nbsp/>=<nbsp/>{<nbsp/>"a"<nbsp/>=&gt;<nbsp/>1,<nbsp/>"c"<nbsp/>=&gt;<nbsp/>2<nbsp/>}</tt></td>
</tr>
<tr>
<td colspan="3"><tt>h2<nbsp/>=<nbsp/>{<nbsp/>"a"<nbsp/>=&gt;<nbsp/>1,<nbsp/>"c"<nbsp/>=&gt;<nbsp/>2,<nbsp/>7<nbsp/>=&gt;<nbsp/>35<nbsp/>}</tt></td>
</tr>
<tr>
<td colspan="3"><tt>h3<nbsp/>=<nbsp/>{<nbsp/>"a"<nbsp/>=&gt;<nbsp/>1,<nbsp/>"c"<nbsp/>=&gt;<nbsp/>2,<nbsp/>7<nbsp/>=&gt;<nbsp/>35<nbsp/>}</tt></td>
</tr>
<tr>
<td colspan="3"><tt>h4<nbsp/>=<nbsp/>{<nbsp/>"a"<nbsp/>=&gt;<nbsp/>1,<nbsp/>"d"<nbsp/>=&gt;<nbsp/>2,<nbsp/>"f"<nbsp/>=&gt;<nbsp/>35<nbsp/>}</tt></td>
</tr>
<tr>
  <td><tt>h1<nbsp/>==<nbsp/>h2</tt></td>
  <td>&#187;</td>
  <td><tt>false</tt></td>
</tr>
<tr>
  <td><tt>h2<nbsp/>==<nbsp/>h3</tt></td>
  <td>&#187;</td>
  <td><tt>true</tt></td>
</tr>
<tr>
  <td><tt>h3<nbsp/>==<nbsp/>h4</tt></td>
  <td>&#187;</td>
  <td><tt>false</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="[ ]" ref="_ob_cb">
      <callseq>
        <obj>hsh</obj>[ <obj>aKeyObject</obj> ] 
        <returns><obj>aValueObject</obj></returns>
      </callseq>
      <desc>
<p/>
      Element Reference---Retrieves the <obj>aValueObject</obj> stored for
      <obj>aKeyObject</obj>.  If not found, returns the <em>default value</em>.
<p/>
<codefragment>
<fullcode><![CDATA[        h = { "a" => 100, "b" => 200 }
        h["a"]
        h["c"]
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>h<nbsp/>=<nbsp/>{<nbsp/>"a"<nbsp/>=&gt;<nbsp/>100,<nbsp/>"b"<nbsp/>=&gt;<nbsp/>200<nbsp/>}</tt></td>
</tr>
<tr>
  <td><tt>h["a"]</tt></td>
  <td>&#187;</td>
  <td><tt>100</tt></td>
</tr>
<tr>
  <td><tt>h["c"]</tt></td>
  <td>&#187;</td>
  <td><tt>nil</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="[ ]=" ref="_ob_cb_eq">
      <callseq>
        <obj>hsh</obj>[ <obj>aKeyObject</obj> ] = <obj>aValueObject</obj>
        <returns><obj>aValueObject</obj></returns>
      </callseq>
      <desc>
<p/>
      Element Assignment---Associates the value given by
      <obj>aValueObject</obj> with the key given by <obj>aKeyObject</obj>.
      <obj>aKeyObject</obj> should not have its value changed while it is
      in use as a key (a <classname>String</classname> passed as a key will be
      duplicated and frozen).
<p/>
<codefragment>
<fullcode><![CDATA[        h = { "a" => 100, "b" => 200 }
        h["a"] = 9
        h["c"] = 4
        h
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>h<nbsp/>=<nbsp/>{<nbsp/>"a"<nbsp/>=&gt;<nbsp/>100,<nbsp/>"b"<nbsp/>=&gt;<nbsp/>200<nbsp/>}</tt></td>
</tr>
<tr>
<td colspan="3"><tt>h["a"]<nbsp/>=<nbsp/>9</tt></td>
</tr>
<tr>
<td colspan="3"><tt>h["c"]<nbsp/>=<nbsp/>4</tt></td>
</tr>
<tr>
  <td><tt>h</tt></td>
  <td>&#187;</td>
  <td><tt>{"a"=&gt;9,<nbsp/>"b"=&gt;200,<nbsp/>"c"=&gt;4}</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="clear" ref="clear">
      <callseq>
        <obj>hsh</obj>.clear <returns><obj>hsh</obj></returns>
      </callseq>
      <desc>
<p/>
      Removes all key-value pairs from <obj>hsh</obj>.
<p/>
<codefragment>
<fullcode><![CDATA[        h = { "a" => 100, "b" => 200 }
        h.clear
]]></fullcode><rubycode>
<tr>
  <td><tt>h<nbsp/>=<nbsp/>{<nbsp/>"a"<nbsp/>=&gt;<nbsp/>100,<nbsp/>"b"<nbsp/>=&gt;<nbsp/>200<nbsp/>}</tt></td>
  <td>&#187;</td>
  <td><tt>{"a"=&gt;100,<nbsp/>"b"=&gt;200}</tt></td>
</tr>
<tr>
  <td><tt>h.clear</tt></td>
  <td>&#187;</td>
  <td><tt>{}</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="default" ref="default">
      <callseq>
        <obj>hsh</obj>.default <returns><obj>anObject</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns the ``<em>default value</em>''---that is, the value returned for a 
      key that does not exist in the hash.  Defaults to <tt>nil</tt>.
      See also <cim><file>hash</file><front>Hash</front><back>default=</back><mref>default_eq</mref></cim>.
<p/>
      </desc>
    </method>
<p/>
        <method name="default=" ref="default_eq">
      <callseq>
        <obj>hsh</obj>.default = <obj>anObject</obj>
        <returns><obj>hsh</obj></returns>
      </callseq>
      <desc>
<p/>
      Sets the ``<em>default value</em>''---that is, the value returned for a 
      key that does not exist in the hash.  Defaults to <tt>nil</tt>.
<p/>
<codefragment>
<fullcode><![CDATA[        h = { "a" => 100, "b" => 200 }
        h.default = "Go fish"
        h["a"]
        h["z"]
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>h<nbsp/>=<nbsp/>{<nbsp/>"a"<nbsp/>=&gt;<nbsp/>100,<nbsp/>"b"<nbsp/>=&gt;<nbsp/>200<nbsp/>}</tt></td>
</tr>
<tr>
<td colspan="3"><tt>h.default<nbsp/>=<nbsp/>"Go<nbsp/>fish"</tt></td>
</tr>
<tr>
  <td><tt>h["a"]</tt></td>
  <td>&#187;</td>
  <td><tt>100</tt></td>
</tr>
<tr>
  <td><tt>h["z"]</tt></td>
  <td>&#187;</td>
  <td><tt>"Go<nbsp/>fish"</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="delete" ref="delete">
      <callseq>
                <obj>hsh</obj>.delete( <obj>aKeyObject</obj> )
          <returns><obj>aValueObject</obj></returns><br/><obj>hsh</obj>.delete( <obj>aKeyObject</obj> ) <block>{| aKeyObject | <blockbody>block</blockbody> }</block>
<p/>
          <returns><obj>aValueObject</obj></returns>
<p/>
      </callseq>
      <desc>
<p/>
      Deletes and returns a key-value pair from <obj>hsh</obj> whose key is equal to
      <obj>aKeyObject</obj>.  If the key is not found, returns
      the <em>default value</em>.  If the optional code block is given
      and the key is not found,  pass in the key and return
      the result of <obj>block</obj>.
<p/>
<codefragment>
<fullcode><![CDATA[        h = { "a" => 100, "b" => 200 }
        h.delete("a")
        h.delete("z")
        h.delete("z") { |el| "#{el} not found" }
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>h<nbsp/>=<nbsp/>{<nbsp/>"a"<nbsp/>=&gt;<nbsp/>100,<nbsp/>"b"<nbsp/>=&gt;<nbsp/>200<nbsp/>}</tt></td>
</tr>
<tr>
  <td><tt>h.delete("a")</tt></td>
  <td>&#187;</td>
  <td><tt>100</tt></td>
</tr>
<tr>
  <td><tt>h.delete("z")</tt></td>
  <td>&#187;</td>
  <td><tt>nil</tt></td>
</tr>
<tr>
  <td><tt>h.delete("z")<nbsp/>{<nbsp/>|el|<nbsp/>"#{el}<nbsp/>not<nbsp/>found"<nbsp/>}</tt></td>
  <td>&#187;</td>
  <td><tt>"z<nbsp/>not<nbsp/>found"</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="delete_if" ref="delete_if">
      <callseq>
        <obj>hsh</obj>.delete_if <block>{| key, value | <blockbody>block</blockbody> }</block>
<p/>
        <returns><obj>hsh</obj></returns>
      </callseq>
      <desc>
<p/>
      Deletes every key-value pair from <obj>hsh</obj> for which <obj>block</obj>
      evaluates to <const>true</const>. 
<p/>
<codefragment>
<fullcode><![CDATA[        h = { "a" => 100, "b" => 200, "c" => 300 }
        h.delete_if {|key, value| key >= "b" }
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>h<nbsp/>=<nbsp/>{<nbsp/>"a"<nbsp/>=&gt;<nbsp/>100,<nbsp/>"b"<nbsp/>=&gt;<nbsp/>200,<nbsp/>"c"<nbsp/>=&gt;<nbsp/>300<nbsp/>}</tt></td>
</tr>
<tr>
  <td><tt>h.delete_if<nbsp/>{|key,<nbsp/>value|<nbsp/>key<nbsp/>&gt;=<nbsp/>"b"<nbsp/>}</tt></td>
  <td>&#187;</td>
  <td><tt>{"a"=&gt;100}</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="each" ref="each">
      <callseq>
        <obj>hsh</obj>.each <block>{| key, value | <blockbody>block</blockbody> }</block>
 <returns><obj>hsh</obj></returns>
      </callseq>
      <desc>
<p/>
      Calls <obj>block</obj> once for each key in <obj>hsh</obj>, passing the key
      and value as parameters.
<p/>
<codefragment>
<alltt><fullcode><![CDATA[        h = { "a" => 100, "b" => 200 }
        h.each {|key, value| print key, " is ", value, "\n" }
]]></fullcode>
h<nbsp/>=<nbsp/>{<nbsp/>"a"<nbsp/>=&gt;<nbsp/>100,<nbsp/>"b"<nbsp/>=&gt;<nbsp/>200<nbsp/>}
h.each<nbsp/>{|key,<nbsp/>value|<nbsp/>print<nbsp/>key,<nbsp/>"<nbsp/>is<nbsp/>",<nbsp/>value,<nbsp/>"\n"<nbsp/>}
</alltt>
</codefragment>
<em>produces:</em>
<codefragment><alltt>
a<nbsp/>is<nbsp/>100
b<nbsp/>is<nbsp/>200
</alltt>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="each_key" ref="each_key">
      <callseq>
        <obj>hsh</obj>.each_key <block>{| key | <blockbody>block</blockbody> }</block>
 <returns><obj>hsh</obj></returns>
      </callseq>
      <desc>
<p/>
      Calls <obj>block</obj> once for each key in <obj>hsh</obj>, passing the key
      as a parameter.
<p/>
<codefragment>
<alltt><fullcode><![CDATA[        h = { "a" => 100, "b" => 200 }
        h.each_key {|key| puts key }
]]></fullcode>
h<nbsp/>=<nbsp/>{<nbsp/>"a"<nbsp/>=&gt;<nbsp/>100,<nbsp/>"b"<nbsp/>=&gt;<nbsp/>200<nbsp/>}
h.each_key<nbsp/>{|key|<nbsp/>puts<nbsp/>key<nbsp/>}
</alltt>
</codefragment>
<em>produces:</em>
<codefragment><alltt>
a
b
</alltt>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="each_pair" ref="each_pair">
      <callseq>
        <obj>hsh</obj>.each_pair <block>{| key, value | <blockbody>block</blockbody> }</block>
 <returns><obj>hsh</obj></returns>
      </callseq>
      <desc>
<p/>
      Synonym for <cim><file>hash</file><front>Hash</front><back>each</back><mref>each</mref></cim>.
<p/>
      </desc>
    </method>
<p/>
        <method name="each_value" ref="each_value">
      <callseq>
        <obj>hsh</obj>.each_value <block>{| value | <blockbody>block</blockbody> }</block>
 <returns><obj>hsh</obj></returns>
      </callseq>
      <desc>
<p/>
      Calls <obj>block</obj> once for each key in <obj>hsh</obj>, passing the value
      as a parameter.
<p/>
<codefragment>
<alltt><fullcode><![CDATA[        h = { "a" => 100, "b" => 200 }
        h.each_value {|value| puts value }
]]></fullcode>
h<nbsp/>=<nbsp/>{<nbsp/>"a"<nbsp/>=&gt;<nbsp/>100,<nbsp/>"b"<nbsp/>=&gt;<nbsp/>200<nbsp/>}
h.each_value<nbsp/>{|value|<nbsp/>puts<nbsp/>value<nbsp/>}
</alltt>
</codefragment>
<em>produces:</em>
<codefragment><alltt>
100
200
</alltt>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="empty?" ref="empty_qm">
      <callseq>
        <obj>hsh</obj>.empty? <returns><const>true</const> or <const>false</const></returns>
      </callseq>
      <desc>
<p/>
      Returns <const>true</const> if <obj>hsh</obj> contains no key-value pairs.
<p/>
<codefragment>
<fullcode><![CDATA[        {}.empty?
]]></fullcode><rubycode>
<tr>
  <td><tt>{}.empty?</tt></td>
  <td>&#187;</td>
  <td><tt>true</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="fetch" ref="fetch">
      <callseq>
            <obj>hsh</obj>.fetch( <obj>aKeyObject</obj> <opt>, <obj>aDefObject</obj></opt> )
          <returns><obj>anObject</obj></returns><br/><obj>hsh</obj>.fetch( <obj>aKeyObject</obj> ) <block>{| aKeyObject | <blockbody>block</blockbody> }</block>
<p/>
          <returns><obj>anObject</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns a value from the hash for the given key.  If the key
      can't be found, there are several options: With no other
      arguments, it will raise an <exception>IndexError</exception> exception; if
      <obj>aDefObject</obj> is given, then that will be returned;  if the
      optional code block is specified, then that will be run and its
      result returned.
<p/>
<codefragment>
<fullcode><![CDATA[        h = { "a" => 100, "b" => 200 }
        h.fetch("a")
        h.fetch("z", "go fish")
        h.fetch("z") { |el| "go fish, #{el}"}
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>h<nbsp/>=<nbsp/>{<nbsp/>"a"<nbsp/>=&gt;<nbsp/>100,<nbsp/>"b"<nbsp/>=&gt;<nbsp/>200<nbsp/>}</tt></td>
</tr>
<tr>
  <td><tt>h.fetch("a")</tt></td>
  <td>&#187;</td>
  <td><tt>100</tt></td>
</tr>
<tr>
  <td><tt>h.fetch("z",<nbsp/>"go<nbsp/>fish")</tt></td>
  <td>&#187;</td>
  <td><tt>"go<nbsp/>fish"</tt></td>
</tr>
<tr>
  <td><tt>h.fetch("z")<nbsp/>{<nbsp/>|el|<nbsp/>"go<nbsp/>fish,<nbsp/>#{el}"}</tt></td>
  <td>&#187;</td>
  <td><tt>"go<nbsp/>fish,<nbsp/>z"</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      The following example shows that an exception is raised if the
      key is not found and a default value is not supplied.
<p/>
<codefragment>
<alltt><fullcode><![CDATA[        h = { "a" => 100, "b" => 200 }
        h.fetch("z")
]]></fullcode>
h<nbsp/>=<nbsp/>{<nbsp/>"a"<nbsp/>=&gt;<nbsp/>100,<nbsp/>"b"<nbsp/>=&gt;<nbsp/>200<nbsp/>}
h.fetch("z")
</alltt>
</codefragment>
<em>produces:</em>
<codefragment><alltt>
prog.rb:2:in<nbsp/>`fetch':<nbsp/>key<nbsp/>not<nbsp/>found<nbsp/>(IndexError)
	from<nbsp/>prog.rb:2
</alltt>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="has_key?" ref="has_key_qm">
      <callseq>
        <obj>hsh</obj>.has_key?( <obj>aKeyObject</obj> )
        <returns><const>true</const> or <const>false</const></returns>
      </callseq>
      <desc>
<p/>
      Returns <const>true</const> if the given key is present in <obj>hsh</obj>.
<p/>
<codefragment>
<fullcode><![CDATA[        h = { "a" => 100, "b" => 200 }
        h.has_key?("a")
        h.has_key?("z")
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>h<nbsp/>=<nbsp/>{<nbsp/>"a"<nbsp/>=&gt;<nbsp/>100,<nbsp/>"b"<nbsp/>=&gt;<nbsp/>200<nbsp/>}</tt></td>
</tr>
<tr>
  <td><tt>h.has_key?("a")</tt></td>
  <td>&#187;</td>
  <td><tt>true</tt></td>
</tr>
<tr>
  <td><tt>h.has_key?("z")</tt></td>
  <td>&#187;</td>
  <td><tt>false</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="has_value?" ref="has_value_qm">
      <callseq>
        <obj>hsh</obj>.has_value?( <obj>aValueObject</obj> )
        <returns><const>true</const> or <const>false</const></returns>
      </callseq>
      <desc>
<p/>
      Returns <const>true</const> if the given value is present for some key in
      <obj>hsh</obj>.
<p/>
<codefragment>
<fullcode><![CDATA[        h = { "a" => 100, "b" => 200 }
        h.has_value?(100)
        h.has_value?(999)
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>h<nbsp/>=<nbsp/>{<nbsp/>"a"<nbsp/>=&gt;<nbsp/>100,<nbsp/>"b"<nbsp/>=&gt;<nbsp/>200<nbsp/>}</tt></td>
</tr>
<tr>
  <td><tt>h.has_value?(100)</tt></td>
  <td>&#187;</td>
  <td><tt>true</tt></td>
</tr>
<tr>
  <td><tt>h.has_value?(999)</tt></td>
  <td>&#187;</td>
  <td><tt>false</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="include?" ref="include_qm">
      <callseq>
        <obj>hsh</obj>.include?( <obj>aKeyObject</obj> )
        <returns><const>true</const> or <const>false</const></returns>
      </callseq>
      <desc>
<p/>
      Synonym for <cim><file>hash</file><front>Hash</front><back>has_key?</back><mref>has_key_qm</mref></cim>.
<p/>
      </desc>
    </method>
<p/>
        <method name="index" ref="index">
      <callseq>
        <obj>hsh</obj>.index( <obj>aValueObject</obj> )
        <returns><obj>aKeyObject</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns the key for a given value.  If not found, returns the
      <em>default value</em>.
<p/>
<codefragment>
<fullcode><![CDATA[        h = { "a" => 100, "b" => 200 }
        h.index(200)
        h.index(999)
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>h<nbsp/>=<nbsp/>{<nbsp/>"a"<nbsp/>=&gt;<nbsp/>100,<nbsp/>"b"<nbsp/>=&gt;<nbsp/>200<nbsp/>}</tt></td>
</tr>
<tr>
  <td><tt>h.index(200)</tt></td>
  <td>&#187;</td>
  <td><tt>"b"</tt></td>
</tr>
<tr>
  <td><tt>h.index(999)</tt></td>
  <td>&#187;</td>
  <td><tt>nil</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="indexes" ref="indexes">
      <callseq>
        <obj>hsh</obj>.indexes( <optn><obj>key</obj></optn> )
        <returns><obj>anArray</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns a new array consisting of values for the given key(s).
      Will insert the <em>default value</em> for keys that are not found.
<p/>
<codefragment>
<fullcode><![CDATA[        h = { "a" => 100, "b" => 200, "c" => 300 }
        h.indexes("a", "c")
        h.indexes("a", "c", "z")
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>h<nbsp/>=<nbsp/>{<nbsp/>"a"<nbsp/>=&gt;<nbsp/>100,<nbsp/>"b"<nbsp/>=&gt;<nbsp/>200,<nbsp/>"c"<nbsp/>=&gt;<nbsp/>300<nbsp/>}</tt></td>
</tr>
<tr>
  <td><tt>h.indexes("a",<nbsp/>"c")</tt></td>
  <td>&#187;</td>
  <td><tt>[100,<nbsp/>300]</tt></td>
</tr>
<tr>
  <td><tt>h.indexes("a",<nbsp/>"c",<nbsp/>"z")</tt></td>
  <td>&#187;</td>
  <td><tt>[100,<nbsp/>300,<nbsp/>nil]</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="indices" ref="indices">
      <callseq>
        <obj>hsh</obj>.indices( <optn><obj>key</obj></optn> )
        <returns><obj>anArray</obj></returns>
      </callseq>
      <desc>
<p/>
      Synonym for <cim><file>hash</file><front>Hash</front><back>indexes</back><mref>indexes</mref></cim>.
<p/>
      </desc>
    </method>
<p/>
        <method name="invert" ref="invert">
      <callseq>
        <obj>hsh</obj>.invert <returns><obj>aHash</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns a new hash created by using <obj>hsh</obj>'s values as keys, and the
      keys as values.
<p/>
<codefragment>
<fullcode><![CDATA[        h = { "n" => 100, "m" => 100, "y" => 300, "d" => 200, "a" => 0 }
        h.invert
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>h<nbsp/>=<nbsp/>{<nbsp/>"n"<nbsp/>=&gt;<nbsp/>100,<nbsp/>"m"<nbsp/>=&gt;<nbsp/>100,<nbsp/>"y"<nbsp/>=&gt;<nbsp/>300,<nbsp/>"d"<nbsp/>=&gt;<nbsp/>200,<nbsp/>"a"<nbsp/>=&gt;<nbsp/>0<nbsp/>}</tt></td>
</tr>
<tr>
  <td><tt>h.invert</tt></td>
  <td>&#187;</td>
  <td><tt>{0=&gt;"a",<nbsp/>100=&gt;"n",<nbsp/>200=&gt;"d",<nbsp/>300=&gt;"y"}</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="key?" ref="key_qm">
      <callseq>
        <obj>hsh</obj>.key?( <obj>aKeyObject</obj> )
      <returns><const>true</const> or <const>false</const></returns>
      </callseq>
      <desc>
<p/>
      Synonym for <cim><file>hash</file><front>Hash</front><back>has_key?</back><mref>has_key_qm</mref></cim>.
<p/>
      </desc>
    </method>
<p/>
        <method name="keys" ref="keys">
      <callseq>
        <obj>hsh</obj>.keys <returns><obj>anArray</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns a new array populated with the keys from this hash.
      See also <cim><file>hash</file><front>Hash</front><back>values</back><mref>values</mref></cim>.
<p/>
<codefragment>
<fullcode><![CDATA[        h = { "a" => 100, "b" => 200, "c" => 300, "d" => 400 }
        h.keys
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>h<nbsp/>=<nbsp/>{<nbsp/>"a"<nbsp/>=&gt;<nbsp/>100,<nbsp/>"b"<nbsp/>=&gt;<nbsp/>200,<nbsp/>"c"<nbsp/>=&gt;<nbsp/>300,<nbsp/>"d"<nbsp/>=&gt;<nbsp/>400<nbsp/>}</tt></td>
</tr>
<tr>
  <td><tt>h.keys</tt></td>
  <td>&#187;</td>
  <td><tt>["a",<nbsp/>"b",<nbsp/>"c",<nbsp/>"d"]</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="length" ref="length">
      <callseq>
        <obj>hsh</obj>.length <returns><obj>aFixnum</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns the number of key-value pairs in the hash.
<p/>
<codefragment>
<fullcode><![CDATA[        h = { "d" => 100, "a" => 200, "v" => 300, "e" => 400 }
        h.length
        h.delete("a")
        h.length
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>h<nbsp/>=<nbsp/>{<nbsp/>"d"<nbsp/>=&gt;<nbsp/>100,<nbsp/>"a"<nbsp/>=&gt;<nbsp/>200,<nbsp/>"v"<nbsp/>=&gt;<nbsp/>300,<nbsp/>"e"<nbsp/>=&gt;<nbsp/>400<nbsp/>}</tt></td>
</tr>
<tr>
  <td><tt>h.length</tt></td>
  <td>&#187;</td>
  <td><tt>4</tt></td>
</tr>
<tr>
  <td><tt>h.delete("a")</tt></td>
  <td>&#187;</td>
  <td><tt>200</tt></td>
</tr>
<tr>
  <td><tt>h.length</tt></td>
  <td>&#187;</td>
  <td><tt>3</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="member?" ref="member_qm">
      <callseq>
        <obj>hsh</obj>.member?( <obj>aKeyObject</obj> )
        <returns><const>true</const> or <const>false</const></returns>
      </callseq>
      <desc>
<p/>
      Synonym for <cim><file>hash</file><front>Hash</front><back>has_key?</back><mref>has_key_qm</mref></cim>.
<p/>
      </desc>
    </method>
<p/>
        <method name="rehash" ref="rehash">
      <callseq>
        <obj>hsh</obj>.rehash <returns><obj>hsh</obj></returns>
      </callseq>
      <desc>
<p/>
      Rebuilds the hash based on the current hash values for each key.
      If values of key objects have changed since they were inserted,
      this method will reindex <obj>hsh</obj>.
      If <cim><file>hash</file><front>Hash</front><back>rehash</back><mref>rehash</mref></cim> is called while an
      iterator is traversing the hash, an <exception>IndexError</exception> will be
      raised in the iterator.
<p/>
<codefragment>
<fullcode><![CDATA[        a = [ "a", "b" ]
        c = [ "c", "d" ]
        h = { a => 100, c => 300 }
        h[a]
        a[0] = "z"
        h[a]
        h.rehash
        h[a]
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>a<nbsp/>=<nbsp/>[<nbsp/>"a",<nbsp/>"b"<nbsp/>]</tt></td>
</tr>
<tr>
<td colspan="3"><tt>c<nbsp/>=<nbsp/>[<nbsp/>"c",<nbsp/>"d"<nbsp/>]</tt></td>
</tr>
<tr>
<td colspan="3"><tt>h<nbsp/>=<nbsp/>{<nbsp/>a<nbsp/>=&gt;<nbsp/>100,<nbsp/>c<nbsp/>=&gt;<nbsp/>300<nbsp/>}</tt></td>
</tr>
<tr>
  <td><tt>h[a]</tt></td>
  <td>&#187;</td>
  <td><tt>100</tt></td>
</tr>
<tr>
<td colspan="3"><tt>a[0]<nbsp/>=<nbsp/>"z"</tt></td>
</tr>
<tr>
  <td><tt>h[a]</tt></td>
  <td>&#187;</td>
  <td><tt>nil</tt></td>
</tr>
<tr>
  <td><tt>h.rehash</tt></td>
  <td>&#187;</td>
  <td><tt>{["z",<nbsp/>"b"]=&gt;100,<nbsp/>["c",<nbsp/>"d"]=&gt;300}</tt></td>
</tr>
<tr>
  <td><tt>h[a]</tt></td>
  <td>&#187;</td>
  <td><tt>100</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="reject" ref="reject">
      <callseq>
        <obj>hsh</obj>.reject <block>{| key, value | <blockbody>block</blockbody> }</block>
<p/>
        <returns><obj>aHash</obj></returns>
      </callseq>
      <desc>
<p/>
      Same as <cim><file>hash</file><front>Hash</front><back>delete_if</back><mref>delete_if</mref></cim>, but works on (and returns) a 
      copy of the <obj>hsh</obj>. Equivalent to <tt><obj>hsh</obj>.dup.delete_if</tt>.
<p/>
      </desc>
    </method>
<p/>
        <method name="reject!" ref="reject_oh">
      <callseq>
        <obj>hsh</obj>.reject! <block>{| key, value | <blockbody>block</blockbody> }</block>
<p/>
        <returns><obj>hsh</obj> or <tt>nil</tt></returns>
      </callseq>
      <desc>
<p/>
      Equivalent to <cim><file>hash</file><front>Hash</front><back>delete_if</back><mref>delete_if</mref></cim>, but returns <tt>nil</tt> if no
      changes were made.
<p/>
      </desc>
    </method>
<p/>
        <method name="replace" ref="replace">
      <callseq>
        <obj>hsh</obj>.replace( <obj>anOtherHash</obj> )
        <returns><obj>hsh</obj></returns>
      </callseq>
      <desc>
<p/>
      Replaces the contents of <obj>hsh</obj> with the contents of
      <obj>anOtherHash</obj>.
<p/>
<codefragment>
<fullcode><![CDATA[        h = { "a" => 100, "b" => 200 }
        h.replace({ "c" => 300, "d" => 400 })
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>h<nbsp/>=<nbsp/>{<nbsp/>"a"<nbsp/>=&gt;<nbsp/>100,<nbsp/>"b"<nbsp/>=&gt;<nbsp/>200<nbsp/>}</tt></td>
</tr>
<tr>
  <td><tt>h.replace({<nbsp/>"c"<nbsp/>=&gt;<nbsp/>300,<nbsp/>"d"<nbsp/>=&gt;<nbsp/>400<nbsp/>})</tt></td>
  <td>&#187;</td>
  <td><tt>{"c"=&gt;300,<nbsp/>"d"=&gt;400}</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="shift" ref="shift">
      <callseq>
        <obj>hsh</obj>.shift <returns><obj>anArray</obj> or <tt>nil</tt></returns>
      </callseq>
      <desc>
<p/>
      Removes a key-value pair
      from <obj>hsh</obj>
      and returns it as the two-item array <tt>[</tt>
      <obj>key, value</obj> <tt>]</tt>, or <tt>nil</tt> if the
      hash is empty. 
<p/>
<codefragment>
<fullcode><![CDATA[        h = { 1 => "a", 2 => "b", 3 => "c" }
        h.shift
        h
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>h<nbsp/>=<nbsp/>{<nbsp/>1<nbsp/>=&gt;<nbsp/>"a",<nbsp/>2<nbsp/>=&gt;<nbsp/>"b",<nbsp/>3<nbsp/>=&gt;<nbsp/>"c"<nbsp/>}</tt></td>
</tr>
<tr>
  <td><tt>h.shift</tt></td>
  <td>&#187;</td>
  <td><tt>[1,<nbsp/>"a"]</tt></td>
</tr>
<tr>
  <td><tt>h</tt></td>
  <td>&#187;</td>
  <td><tt>{2=&gt;"b",<nbsp/>3=&gt;"c"}</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="size" ref="size">
      <callseq>
        <obj>hsh</obj>.size <returns><obj>aFixnum</obj></returns>
      </callseq>
      <desc>
<p/>
      Synonym for <cim><file>hash</file><front>Hash</front><back>length</back><mref>length</mref></cim>.
<p/>
      </desc>
    </method>
<p/>
        <method name="sort" ref="sort">
      <callseq>
        <obj>hsh</obj>.sort 
        <returns><obj>anArray</obj></returns> <br/><obj>hsh</obj>.sort <block>{| a, b | <blockbody>block</blockbody> }</block>
<p/>
        <returns><obj>anArray</obj></returns>
<p/>
      </callseq>
      <desc>
<p/>
      Converts <obj>hsh</obj> to a nested array of <tt>[</tt> <obj>key, value</obj>
      <tt>]</tt> arrays and sorts it, using <cim><file>array</file><front>Array</front><back>sort</back><mref>sort</mref></cim>.
<p/>
<codefragment>
<fullcode><![CDATA[        h = { "a" => 20, "b" => 30, "c" => 10  }
        h.sort
        h.sort {|a,b| a[1]<=>b[1]}
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>h<nbsp/>=<nbsp/>{<nbsp/>"a"<nbsp/>=&gt;<nbsp/>20,<nbsp/>"b"<nbsp/>=&gt;<nbsp/>30,<nbsp/>"c"<nbsp/>=&gt;<nbsp/>10<nbsp/><nbsp/>}</tt></td>
</tr>
<tr>
  <td><tt>h.sort</tt></td>
  <td>&#187;</td>
  <td><tt>[["a",<nbsp/>20],<nbsp/>["b",<nbsp/>30],<nbsp/>["c",<nbsp/>10]]</tt></td>
</tr>
<tr>
  <td><tt>h.sort<nbsp/>{|a,b|<nbsp/>a[1]&lt;=&gt;b[1]}</tt></td>
  <td>&#187;</td>
  <td><tt>[["c",<nbsp/>10],<nbsp/>["a",<nbsp/>20],<nbsp/>["b",<nbsp/>30]]</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="store" ref="store">
      <callseq>
        <obj>hsh</obj>.store( <obj>aKeyObject, aValueObject</obj> ) 
        <returns><obj>aValueObject</obj></returns>
      </callseq>
      <desc>
<p/>
      Synonym for Element Assignment (<cim><file>hash</file><front>Hash</front><back>[]=</back><mref>_ob_cb_eq</mref></cim>).
<p/>
      </desc>
    </method>
<p/>
        <method name="to_a" ref="to_a">
      <callseq>
        <obj>hsh</obj>.to_a 
        <returns><obj>anArray</obj></returns>
      </callseq>
      <desc>
<p/>
      Converts <obj>hsh</obj> to a nested array of <tt>[</tt> <obj>key, value</obj>
      <tt>]</tt> arrays.  
<p/>
<codefragment>
<fullcode><![CDATA[        h = { "c" => 300, "a" => 100, "d" => 400, "c" => 300  }
        h.to_a
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>h<nbsp/>=<nbsp/>{<nbsp/>"c"<nbsp/>=&gt;<nbsp/>300,<nbsp/>"a"<nbsp/>=&gt;<nbsp/>100,<nbsp/>"d"<nbsp/>=&gt;<nbsp/>400,<nbsp/>"c"<nbsp/>=&gt;<nbsp/>300<nbsp/><nbsp/>}</tt></td>
</tr>
<tr>
  <td><tt>h.to_a</tt></td>
  <td>&#187;</td>
  <td><tt>[["a",<nbsp/>100],<nbsp/>["c",<nbsp/>300],<nbsp/>["d",<nbsp/>400]]</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="to_s" ref="to_s">
      <callseq>
        <obj>hsh</obj>.to_s <returns><obj>aString</obj></returns>
      </callseq>
      <desc>
<p/>
      Converts <obj>hsh</obj> to a string by converting the hash to an array
      of <tt>[</tt> <obj>key, value</obj> <tt>]</tt> pairs and then converting that array to a string using
      <cim><file>array</file><front>Array</front><back>join</back><mref>join</mref></cim> with the default separator.
<p/>
<codefragment>
<fullcode><![CDATA[        h = { "c" => 300, "a" => 100, "d" => 400, "c" => 300  }
        h.to_s
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>h<nbsp/>=<nbsp/>{<nbsp/>"c"<nbsp/>=&gt;<nbsp/>300,<nbsp/>"a"<nbsp/>=&gt;<nbsp/>100,<nbsp/>"d"<nbsp/>=&gt;<nbsp/>400,<nbsp/>"c"<nbsp/>=&gt;<nbsp/>300<nbsp/><nbsp/>}</tt></td>
</tr>
<tr>
  <td><tt>h.to_s</tt></td>
  <td>&#187;</td>
  <td><tt>"a100c300d400"</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="update" ref="update">
      <callseq>
        <obj>hsh</obj>.update( <obj>anOtherHash</obj> )
        <returns><obj>hsh</obj></returns>
      </callseq>
      <desc>
<p/>
     Adds the contents of <obj>anOtherHash</obj> to <obj>hsh</obj>, overwriting
     entries with duplicate keys  with those from <obj>anOtherHash</obj>.
<p/>
<codefragment>
<fullcode><![CDATA[        h1 = { "a" => 100, "b" => 200 }
        h2 = { "b" => 254, "c" => 300 }
        h1.update(h2)
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>h1<nbsp/>=<nbsp/>{<nbsp/>"a"<nbsp/>=&gt;<nbsp/>100,<nbsp/>"b"<nbsp/>=&gt;<nbsp/>200<nbsp/>}</tt></td>
</tr>
<tr>
<td colspan="3"><tt>h2<nbsp/>=<nbsp/>{<nbsp/>"b"<nbsp/>=&gt;<nbsp/>254,<nbsp/>"c"<nbsp/>=&gt;<nbsp/>300<nbsp/>}</tt></td>
</tr>
<tr>
  <td><tt>h1.update(h2)</tt></td>
  <td>&#187;</td>
  <td><tt>{"a"=&gt;100,<nbsp/>"b"=&gt;254,<nbsp/>"c"=&gt;300}</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="value?" ref="value_qm">
      <callseq>
        <obj>hsh</obj>.value?( <obj>aValueObject</obj> )
        <returns><const>true</const> or <const>false</const></returns>
      </callseq>
      <desc>
<p/>
      Synonym for <cim><file>hash</file><front>Hash</front><back>has_value?</back><mref>has_value_qm</mref></cim>.
<p/>
      </desc>
    </method>
<p/>
        <method name="values" ref="values">
      <callseq>
        <obj>hsh</obj>.values <returns><obj>anArray</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns a new array populated with the values from <obj>hsh</obj>.
      See also <cim><file>hash</file><front>Hash</front><back>keys</back><mref>keys</mref></cim>.
<p/>
<codefragment>
<fullcode><![CDATA[        h = { "a" => 100, "b" => 200, "c" => 300 }
        h.values
]]></fullcode><rubycode>
<tr>
<td colspan="3"><tt>h<nbsp/>=<nbsp/>{<nbsp/>"a"<nbsp/>=&gt;<nbsp/>100,<nbsp/>"b"<nbsp/>=&gt;<nbsp/>200,<nbsp/>"c"<nbsp/>=&gt;<nbsp/>300<nbsp/>}</tt></td>
</tr>
<tr>
  <td><tt>h.values</tt></td>
  <td>&#187;</td>
  <td><tt>[100,<nbsp/>200,<nbsp/>300]</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
  </methods>
<p/>
</class>
</ppdoc>
