module Equatable

Make it easy to define equality and hash methods.

Constants

VERSION

Attributes

comparison_attrs[R]

Holds all attributes used for comparison.

@return [Array<Symbol>]

@api private

Public Class Methods

included(base) click to toggle source

Hook into module inclusion.

@param [Module] base

the module or class including Equatable

@return [self]

@api private

Calls superclass method
# File lib/equatable.rb, line 14
def self.included(base)
  super
  base.extend(self)
  base.class_eval do
    include Methods
    define_methods
  end
end

Public Instance Methods

attr_reader(*args) click to toggle source

Objects that include this module are assumed to be value objects. It is also assumed that the only values that affect the results of equality comparison are the values of the object's attributes.

@param [Array<Symbol>] *args

@return [undefined]

@api public

Calls superclass method
# File lib/equatable.rb, line 39
def attr_reader(*args)
  super
  comparison_attrs.concat(args)
end
inherited(subclass) click to toggle source

Copy the #comparison_attrs into the subclass.

@param [Class] subclass

@api private

Calls superclass method
# File lib/equatable.rb, line 49
def inherited(subclass)
  super
  subclass.instance_variable_set(:@comparison_attrs, comparison_attrs.dup)
end