equitable.rb

Path: lib/standard/facets/equitable.rb
Last Update: Wed Apr 17 08:26:34 +0000 2013

Equitable

This mixin provides methods of equality based on a single identity method which must return a list of accessors used as the identity keys.

It also provides a "shortcut" for creating the identity method based on given accessors and returns the Equitable module for inclusion.

  include Equitable(:a, :b)

is equivalent to including a module containing:

  def ==(other)
    self.a == other.a && self.b == other.b
  end

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

  def hash()
    self.a.hash ^ self.b.hash
  end

[Validate]