Class: Matchi::Equal

Inherits:
BasicObject
Defined in:
lib/matchi/equal.rb

Overview

Identity matcher.

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ Equal

Initialize the matcher with an object.

Examples:

The number 42 matcher

Matchi::Equal.new(42)

Parameters:

  • expected (#equal?)

    An expected object.



10
11
12
# File 'lib/matchi/equal.rb', line 10

def initialize(expected)
  @expected = expected
end

Instance Method Details

#matches?Boolean

Returns Comparison between actual and expected values.

Examples:

Is it equal to :foo?

equal = Matchi::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.



21
22
23
# File 'lib/matchi/equal.rb', line 21

def matches?
  @expected.equal?(yield)
end