Module: Equalizer::InstanceMethods Private

Defined in:
lib/equalizer.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Instance methods mixed into classes that include an Equalizer module

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Equality comparison allowing subclasses

Parameters:

  • other (Object)

    object to compare

Returns:

  • (Boolean)

    true if other is_a? same class with equal attributes



79
80
81
82
# File 'lib/equalizer.rb', line 79

def ==(other)
  other.is_a?(self.class) &&
    cmp?(:==, other)
end

#deconstructArray

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Array deconstruction for pattern matching

Returns:

  • (Array)

    attribute values in order



103
104
105
# File 'lib/equalizer.rb', line 103

def deconstruct
  equalizer_keys.map { |key| public_send(key) }
end

#deconstruct_keys(requested) ⇒ Hash{Symbol => Object}

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Hash deconstruction for pattern matching

Parameters:

  • requested (Array<Symbol>, nil)

    keys to include, or nil for all

Returns:

  • (Hash{Symbol => Object})

    requested attribute key-value pairs



111
112
113
114
# File 'lib/equalizer.rb', line 111

def deconstruct_keys(requested)
  subset = requested.nil? ? equalizer_keys : equalizer_keys & requested
  subset.to_h { |key| [key, public_send(key)] }
end

#eql?(other) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Strict equality requiring exact class match

Parameters:

  • other (Object)

    object to compare

Returns:

  • (Boolean)

    true if other is exact same class with eql? attributes



88
89
90
91
# File 'lib/equalizer.rb', line 88

def eql?(other)
  other.instance_of?(self.class) &&
    cmp?(:eql?, other)
end

#hashInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Hash code based on class and attribute values

Returns:

  • (Integer)

    hash code



96
97
98
# File 'lib/equalizer.rb', line 96

def hash
  [self.class, *deconstruct].hash
end