Module: Equalizer::Methods

Defined in:
lib/equalizer.rb

Overview

The comparison methods

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Boolean

Compare the object with other object for equivalency

Examples:

object == other  # => true or false

Parameters:

  • other (Object)

    the other object to compare with

Returns:

  • (Boolean)


113
114
115
116
# File 'lib/equalizer.rb', line 113

def ==(other)
  other = coerce(other) if respond_to?(:coerce, true)
  other.kind_of?(self.class) && cmp?(__method__, other)
end

#eql?(other) ⇒ Boolean

Compare the object with other object for equality

Examples:

object.eql?(other)  # => true or false

Parameters:

  • other (Object)

    the other object to compare with

Returns:

  • (Boolean)


98
99
100
# File 'lib/equalizer.rb', line 98

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