Class: Fear::TryPatternMatch Private

Inherits:
PatternMatch show all
Defined in:
lib/fear/try_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::SuccessPatternMatch and Fear::FailurePatternMatch

Try pattern matcher

Direct Known Subclasses

FailurePatternMatch, SuccessPatternMatch

Constant Summary collapse

SUCCESS_EXTRACTOR =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

:get.to_proc
FAILURE_EXTRACTOR =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

:exception.to_proc

Instance Attribute Summary

Attributes inherited from PatternMatch

#result

Instance Method Summary collapse

Methods inherited from PatternMatch

__new__, #case, #else, #initialize, mixin, new, #or_else, #xcase

Constructor Details

This class inherits a constructor from Fear::PatternMatch

Instance Method Details

#failure(*conditions, &effect) ⇒ Fear::TryPatternMatch

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 Fear::Failure


25
26
27
28
# File 'lib/fear/try_pattern_match.rb', line 25

def failure(*conditions, &effect)
  branch = Fear.case(Fear::Failure, &FAILURE_EXTRACTOR).and_then(Fear.case(*conditions, &effect))
  or_else(branch)
end

#success(*conditions, &effect) ⇒ Fear::TryPatternMatch

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 Fear::Success


16
17
18
19
# File 'lib/fear/try_pattern_match.rb', line 16

def success(*conditions, &effect)
  branch = Fear.case(Fear::Success, &SUCCESS_EXTRACTOR).and_then(Fear.case(*conditions, &effect))
  or_else(branch)
end