<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>Module: Equatable</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />

    <script language="JavaScript" type="text/javascript">
    // <![CDATA[

        function toggleSource( id )
        {
          var elem
          var link

          if( document.getElementById )
          {
            elem = document.getElementById( id )
            link = document.getElementById( "l_" + id )
          }
          else if ( document.all )
          {
            elem = eval( "document.all." + id )
            link = eval( "document.all.l_" + id )
          }
          else
            return false;

          if( elem.style.display == "block" )
          {
            elem.style.display = "none"
            link.innerHTML = "show source"
          }
          else
          {
            elem.style.display = "block"
            link.innerHTML = "hide source"
          }
        }

        function openCode( url )
        {
          window.open( url, "SOURCE_CODE", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=480,width=750" ).focus();
        }
      // ]]>
    </script>
  </head>

  <body>
  <table width="100%" border='0' cellpadding='0' cellspacing='0' class='banner'><tr>
  <td class="file-title"><span class="file-title-prefix">Module</span><br />Equatable</td>
  <td align="right">
    <table cellspacing="0" cellpadding="2">
      <tr valign="top">
        <td>In:</td>
        <td>
<a href="../files/lib/facets/equatable_rb.html">lib/facets/equatable.rb</a>
        </td>
      </tr>
         </table>
        </td>
        </tr>
      </table>
 <!-- banner header -->

  <div id="bodyContent">
      <div id="content">

  <div class="description"><h1><a href="Equatable.html">Equatable</a></h1>
<p>
This mixin provides methods of equality based on a single identity method
which must return a list of accessors used as the identity keys.
</p>
<p>
<a href="It.html">It</a> also provides a &quot;shortcut&quot; for creating
the identity method based on given accessors and returns the <a
href="Equatable.html">Equatable</a> module for inclusion.
</p>
<pre>
  include Equatable(:a, :b)
</pre>
<p>
is equivalent to including a module containing:
</p>
<pre>
  def ==(other)
    self.a == other.a &amp;&amp; self.b == other.b
  end

  def eql?(other)
    self.a.eql?(other.a) &amp;&amp; self.b.eql?(other.b)
  end

  def hash()
    self.a.hash ^ self.b.hash
  end
</pre>
</div>



  <div class="sectiontitle">Methods</div>
  <ul>
  <li><a href="#M000921">==</a></li>
  <li><a href="#M000922">eql?</a></li>
  <li><a href="#M000923">hash</a></li>
  <li><a href="#M000920">identify</a></li>
  </ul>






<div class="sectiontitle">Public Class methods</div>
<div class="method">
  <div class="title">
    <a name="M000920"></a><b>identify</b>(base, *accessors)
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000920_source')" id="l_M000920_source">show source</a> ]</p>
  <div id="M000920_source" class="dyn-source">
<pre>
<span class="ruby-comment cmt"># File lib/facets/equatable.rb, line 73</span>
  <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">identify</span>(<span class="ruby-identifier">base</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">accessors</span>)
    <span class="ruby-identifier">base</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">:define_method</span>, <span class="ruby-identifier">:identity</span>){ <span class="ruby-identifier">accessors</span> }
    <span class="ruby-keyword kw">self</span>
  <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="sectiontitle">Public Instance methods</div>
<div class="method">
  <div class="title">
    <a name="M000921"></a><b>==</b>(o)
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000921_source')" id="l_M000921_source">show source</a> ]</p>
  <div id="M000921_source" class="dyn-source">
<pre>
<span class="ruby-comment cmt"># File lib/facets/equatable.rb, line 78</span>
  <span class="ruby-keyword kw">def</span> <span class="ruby-operator">==</span>(<span class="ruby-identifier">o</span>)
    <span class="ruby-identifier">identity</span>.<span class="ruby-identifier">all?</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">a</span><span class="ruby-operator">|</span> <span class="ruby-identifier">send</span>(<span class="ruby-identifier">a</span>) <span class="ruby-operator">==</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">a</span>) }
  <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000922"></a><b>eql?</b>(o)
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000922_source')" id="l_M000922_source">show source</a> ]</p>
  <div id="M000922_source" class="dyn-source">
<pre>
<span class="ruby-comment cmt"># File lib/facets/equatable.rb, line 82</span>
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">eql?</span>(<span class="ruby-identifier">o</span>)
    <span class="ruby-identifier">identity</span>.<span class="ruby-identifier">all?</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">a</span><span class="ruby-operator">|</span> <span class="ruby-identifier">send</span>(<span class="ruby-identifier">a</span>).<span class="ruby-identifier">eql?</span>(<span class="ruby-identifier">o</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">a</span>)) }
  <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000923"></a><b>hash</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000923_source')" id="l_M000923_source">show source</a> ]</p>
  <div id="M000923_source" class="dyn-source">
<pre>
<span class="ruby-comment cmt"># File lib/facets/equatable.rb, line 86</span>
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">hash</span>
    <span class="ruby-identifier">identity</span>.<span class="ruby-identifier">inject</span>(<span class="ruby-value">0</span>){ <span class="ruby-operator">|</span><span class="ruby-identifier">memo</span>, <span class="ruby-identifier">a</span><span class="ruby-operator">|</span> <span class="ruby-identifier">memo</span> <span class="ruby-operator">^</span> <span class="ruby-identifier">send</span>(<span class="ruby-identifier">a</span>).<span class="ruby-identifier">hash</span> }
  <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
</div>

  </div>

    </body>
</html>