Class: Fear::OptionPatternMatch Private
- Inherits:
-
PatternMatch
- Object
- PatternMatch
- Fear::OptionPatternMatch
- 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
OptionPatternMatch.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::OptionPatternMatch
private
Match against None.
-
#some(*conditions, &effect) ⇒ Fear::OptionPatternMatch
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::OptionPatternMatch
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
42 43 44 45 |
# File 'lib/fear/option_pattern_match.rb', line 42 def none(&effect) branch = Fear.case(Fear::None, &effect) or_else(branch) end |
#some(*conditions, &effect) ⇒ Fear::OptionPatternMatch
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
33 34 35 36 |
# File 'lib/fear/option_pattern_match.rb', line 33 def some(*conditions, &effect) branch = Fear.case(Fear::Some, &:get).and_then(Fear.case(*conditions, &effect)) or_else(branch) end |