Class: Deterministic::PatternMatching::Match
- Defined in:
- lib/deterministic/either/match.rb
Defined Under Namespace
Classes: Matcher
Instance Method Summary collapse
-
#any(value = nil, &result_block) ⇒ Object
catch-all.
-
#initialize(container, context) ⇒ Match
constructor
A new instance of Match.
- #result ⇒ Object
Constructor Details
#initialize(container, context) ⇒ Match
Returns a new instance of Match.
13 14 15 16 17 |
# File 'lib/deterministic/either/match.rb', line 13 def initialize(container, context) @container = container @context = context @collection = [] end |
Instance Method Details
#any(value = nil, &result_block) ⇒ Object
catch-all
34 35 36 |
# File 'lib/deterministic/either/match.rb', line 34 def any(value=nil, &result_block) push(Object, value, result_block) end |
#result ⇒ Object
19 20 21 22 23 |
# File 'lib/deterministic/either/match.rb', line 19 def result matcher = @collection.detect { |m| m.matches?(@container.value) } raise NoMatchError, "No could be made for #{@container}" if matcher.nil? @context.instance_exec(@container.value, &matcher.block) end |