Class: Matchi::Match

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

Overview

**Regular expressions** matcher.

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ Match

Initialize the matcher with an instance of Regexp.

Examples:

Username matcher

Matchi::Match.new(/^[a-z0-9_-]{3,16}$/)

Parameters:

  • expected (#match)

    A regular expression.



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

def initialize(expected)
  @expected = expected
end

Instance Method Details

#matches?Boolean

Returns Comparison between actual and expected values.

Examples:

Is it matching /^foo$/ regex?

match = Matchi::Match.new(/^foo$/)
match.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/match.rb', line 21

def matches?
  @expected.match(yield).nil?.equal?(false)
end