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) ⇒ Match
constructor
A new instance of Match.
- #result ⇒ Object
Constructor Details
#initialize(container) ⇒ Match
12 13 14 15 |
# File 'lib/deterministic/either/match.rb', line 12 def initialize(container) @container = container @collection = [] end |
Instance Method Details
#any(value = nil, &result_block) ⇒ Object
catch-all
32 33 34 |
# File 'lib/deterministic/either/match.rb', line 32 def any(value=nil, &result_block) push(Object, value, result_block) end |
#result ⇒ Object
17 18 19 20 21 |
# File 'lib/deterministic/either/match.rb', line 17 def result matcher = @collection.select { |m| m.matches?(@container.value) }.last raise NoMatchError if matcher.nil? matcher.result(@container.value) end |