Class: Fear::Option::PatternMatch Private
- Inherits:
-
PatternMatch
- Object
- PatternMatch
- Fear::Option::PatternMatch
- Defined in:
- lib/fear/option/pattern_match.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Note:
it has two optimized subclasses Fear::SomePatternMatch
and Fear::NonePatternMatch
Option pattern matcher
@example the same matcher may be defined using block syntax
Option::PatternMatch.new do |m|
m.some(Integer) { |x| x * 2 }
m.some(String) { |x| x.to_i * 2 }
m.none { 'NaN' }
m.else { 'error '}
end
Instance Attribute Summary
Attributes inherited from PatternMatch
Instance Method Summary collapse
-
#none(&effect) ⇒ Fear::Option::PatternMatch
private
Match against None.
-
#some(*conditions, &effect) ⇒ Fear::Option::PatternMatch
private
Match against Some.
Methods inherited from PatternMatch
__new__, #case, #else, #initialize, mixin, new, #or_else
Constructor Details
This class inherits a constructor from Fear::PatternMatch
Instance Method Details
#none(&effect) ⇒ Fear::Option::PatternMatch
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Match against None
41 42 43 44 |
# File 'lib/fear/option/pattern_match.rb', line 41 def none(&effect) branch = Fear.case(Fear::None, &effect) or_else(branch) end |
#some(*conditions, &effect) ⇒ Fear::Option::PatternMatch
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Match against Some
32 33 34 35 |
# File 'lib/fear/option/pattern_match.rb', line 32 def some(*conditions, &effect) branch = Fear.case(Fear::Some, &:get).and_then(Fear.case(*conditions, &effect)) or_else(branch) end |