Class: Matchi::Eql

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

Overview

Equivalence matcher.

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ Eql

Initialize the matcher with an object.

Examples:

The string ‘foo’ matcher

Matchi::Eql.new('foo')

Parameters:

  • expected (#eql?)

    An expected equivalent object.



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

def initialize(expected)
  @expected = expected
end

Instance Method Details

#matches?Boolean

Returns Comparison between actual and expected values.

Examples:

Is it equivalent to ‘foo’?

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



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

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