Class: Deterministic::PatternMatching::Match

Inherits:
Object
  • Object
show all
Defined in:
lib/deterministic/either/match.rb

Defined Under Namespace

Classes: Matcher

Instance Method Summary collapse

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

#resultObject

Raises:



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