Class: Matchi::Change::To
- Inherits:
-
Object
- Object
- Matchi::Change::To
- Defined in:
- lib/matchi/change/to.rb
Overview
Passes when the observed value is not the expected value before the block and is the expected value after it: the value must change to it. The block is always evaluated.
Instance Method Summary collapse
-
#initialize(expected, &state) ⇒ To
constructor
A new instance of To.
- #match? ⇒ Boolean
- #to_s ⇒ String
Constructor Details
#initialize(expected, &state) ⇒ To
Returns a new instance of To.
18 19 20 21 22 23 |
# File 'lib/matchi/change/to.rb', line 18 def initialize(expected, &state) raise ::ArgumentError, "a block must be provided" unless block_given? @expected = expected @state = state end |
Instance Method Details
#match? ⇒ Boolean
28 29 30 31 32 33 34 35 |
# File 'lib/matchi/change/to.rb', line 28 def match? raise ::ArgumentError, "a block must be provided" unless block_given? already = Eq.eql?(@expected, @state.call) yield !already && Eq.eql?(@expected, @state.call) end |
#to_s ⇒ String
38 39 40 |
# File 'lib/matchi/change/to.rb', line 38 def to_s "change to #{@expected.inspect}" end |