Class: Matchi::Matcher::Eql

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

Overview

Equivalence 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) ⇒ Eql

Initialize the matcher with an object.

Examples:

The string ‘foo’ matcher.

Matchi::Matcher::Eql.new('foo')

Parameters:

  • expected (#eql?)

    An expected equivalent object.



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

def initialize(expected)
  @expected = expected
end

Instance Method Details

#matches?Boolean

Boolean comparison between the actual value and the expected value.

Examples:

Is it equivalent to ‘foo’?

eql = Matchi::Matcher::Eql.new('foo')
eql.matches? { 'foo' } # => true

Yield Returns:

  • (#object_id)

    The actual value to compare to the expected one.

Returns:

  • (Boolean)

    Comparison between actual and expected values.



29
30
31
# File 'lib/matchi/matcher/eql.rb', line 29

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