Class: Tzu::Match
- Inherits:
-
Object
- Object
- Tzu::Match
- Defined in:
- lib/tzu/match.rb
Overview
with thanks to github.com/pzol/deterministic
Defined Under Namespace
Classes: Matcher
Instance Method Summary collapse
-
#initialize(outcome, context) ⇒ Match
constructor
A new instance of Match.
-
#invalid(&result_block) ⇒ Object
todo: hash and define_method if more overrides identified.
- #result ⇒ Object
Constructor Details
#initialize(outcome, context) ⇒ Match
Returns a new instance of Match.
5 6 7 |
# File 'lib/tzu/match.rb', line 5 def initialize(outcome, context) @outcome, @context, @collection = outcome, context, [] end |
Instance Method Details
#invalid(&result_block) ⇒ Object
todo: hash and define_method if more overrides identified
22 23 24 |
# File 'lib/tzu/match.rb', line 22 def invalid(&result_block) push('failure', :validation, result_block) end |
#result ⇒ Object
9 10 11 12 13 |
# File 'lib/tzu/match.rb', line 9 def result matcher = @collection.detect { |m| m.matches?(@outcome.type) } raise "No match could be made for #{@outcome}" if matcher.nil? @context.instance_exec(@outcome.result, &matcher.block) end |