Class: Deterministic::PatternMatching::Match
- Inherits:
-
Object
- Object
- 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.
12 13 14 15 16 |
# File 'lib/deterministic/either/match.rb', line 12 def initialize(container, context) @container = container @context = context @collection = [] end |
Instance Method Details
#any(value = nil, &result_block) ⇒ Object
catch-all
33 34 35 |
# File 'lib/deterministic/either/match.rb', line 33 def any(value=nil, &result_block) push(Object, value, result_block) end |
#result ⇒ Object
18 19 20 21 22 |
# File 'lib/deterministic/either/match.rb', line 18 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 |