Class: Matchi::Match
- Inherits:
-
Object
- Object
- Matchi::Match
- Defined in:
- lib/matchi/match.rb
Overview
*Regular expressions* matcher.
Instance Method Summary collapse
-
#initialize(expected) ⇒ Match
constructor
Initialize the matcher with an instance of Regexp.
-
#match? ⇒ Boolean
Boolean comparison between the actual value and the expected value.
-
#to_s ⇒ String
Returns a string representing the matcher.
Constructor Details
#initialize(expected) ⇒ Match
Initialize the matcher with an instance of Regexp.
14 15 16 17 18 |
# File 'lib/matchi/match.rb', line 14 def initialize(expected) raise ::ArgumentError, "expected must respond to match?" unless expected.respond_to?(:match?) @expected = expected end |
Instance Method Details
#match? ⇒ Boolean
Boolean comparison between the actual value and the expected value.
32 33 34 35 36 |
# File 'lib/matchi/match.rb', line 32 def match? raise ::ArgumentError, "a block must be provided" unless block_given? @expected.match?(yield) end |
#to_s ⇒ String
Returns a string representing the matcher.
41 42 43 |
# File 'lib/matchi/match.rb', line 41 def to_s "match #{@expected.inspect}" end |