Class: Matchi::Matcher::Equal

Inherits:
Base
  • Object
show all
Defined in:
lib/matchi/matcher/equal.rb

Overview

Identity matcher.

Instance Attribute Summary

Attributes inherited from Base

#expected

Instance Method Summary collapse

Methods inherited from Base

#inspect, #to_s, to_sym

Constructor Details

#initialize(expected) ⇒ Equal

Initialize the matcher with an object.

Examples:

The number 42 matcher.

Matchi::Matcher::Equal.new(42)

Parameters:

  • expected (#equal?)

    An expected object.



15
16
17
18
# File 'lib/matchi/matcher/equal.rb', line 15

def initialize(expected)
  super()
  @expected = expected
end

Instance Method Details

#matches?Boolean

Boolean comparison between the actual value and the expected value.

Examples:

Is it equal to :foo?

equal = Matchi::Matcher::Equal.new(:foo)
equal.matches? { :foo } # => true

Yield Returns:

  • (#object_id)

    The actual value to compare to the expected one.

Returns:

  • (Boolean)

    Comparison between actual and expected values.



30
31
32
# File 'lib/matchi/matcher/equal.rb', line 30

def matches?(*, **)
  expected.equal?(yield)
end