Class: Deterministic::Either::Match
- Inherits:
-
Object
- Object
- Deterministic::Either::Match
- Defined in:
- lib/deterministic/either/match.rb
Instance Method Summary collapse
- #either(value = nil, &block) ⇒ Object
- #failure(value = nil, &block) ⇒ Object
-
#initialize(either) ⇒ Match
constructor
A new instance of Match.
- #result ⇒ Object
- #success(value = nil, &block) ⇒ Object
Constructor Details
#initialize(either) ⇒ Match
Returns a new instance of Match.
9 10 11 12 |
# File 'lib/deterministic/either/match.rb', line 9 def initialize(either) @either = either @collection = [] end |
Instance Method Details
#either(value = nil, &block) ⇒ Object
22 23 24 |
# File 'lib/deterministic/either/match.rb', line 22 def either(value=nil, &block) q(:either, value, block) end |
#failure(value = nil, &block) ⇒ Object
18 19 20 |
# File 'lib/deterministic/either/match.rb', line 18 def failure(value=nil, &block) q(:failure, value, block) end |
#result ⇒ Object
26 27 28 29 |
# File 'lib/deterministic/either/match.rb', line 26 def result matcher = @collection.select { |m| m.first.call(@either.value) }.last matcher.last.call(@either.value) end |
#success(value = nil, &block) ⇒ Object
14 15 16 |
# File 'lib/deterministic/either/match.rb', line 14 def success(value=nil, &block) q(:success, value, block) end |