### Home Classes Methods

### In Files

- lib/facets/equitable.rb

### Methods

- ::identify
- #==
- #eql?
- #hash

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Random
- Random::ArrayExtensions
- Random::HashExtensions
- Random::IntegerExtensions
- Random::NumericExtensions
- Random::RangeExtensions
- Random::StringExtensions
- Random::StringExtensions::Self
- FileUtils
- FileUtils::DryRun
- FileUtils::NoWrite
- FileUtils::Verbose
- Digest
- Digest::Class
- Digest::Instance
- Multiton
- Multiton::Inclusive
- Multiton::MetaMethods
- URI
- URI::Hash
- URI::Kernel
- Argvector
- Argvector
- ERB
- ERB::OpenTemplate
- Enumerable
- Enumerable::Arguments
- GetoptLong
- GetoptLong::DSL
- Memoizable
- Memoizable::Copy
- Numeric
- Numeric::Multipliers
- Object
- Object::ArgVector
- Timer
- Timer::Dummy
- Array
- BasicObject
- CGI
- Cloneable
- Continuation
- Date
- DateTime
- Equitable
- File
- Find
- Hash
- Instantiable
- Integer
- Interval
- Kernel
- Math
- Module
- Net
- NilClass
- NullClass
- OpEsc
- OpenStruct
- Pathname
- Platform
- Range
- RbConfig
- Set
- Shellwords
- String
- StringScanner
- Time
- Tuple
- YAML
- Zlib

No matching classes.

# 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

### Public Class Methods

identify(base, *accessors) click to toggle source

    # File lib/facets/equitable.rb, line 29
    def self.identify(base, *accessors)
      base.send(:define_method, :identity){ accessors }
      self
    end

### Public Instance Methods

==(o) click to toggle source

    # File lib/facets/equitable.rb, line 34
    def ==(o)
      identity.all?{ |a| send(a) == o.send(a) }
    end

eql?(o) click to toggle source

    # File lib/facets/equitable.rb, line 38
    def eql?(o)
      identity.all?{ |a| send(a).eql?(o.send(a)) }
    end

hash() click to toggle source

    # File lib/facets/equitable.rb, line 42
    def hash
      identity.inject(0){ |memo, a| memo ^ send(a).hash }
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.