Class: Fear::Extractor::Matcher Abstract Private
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Fear::Extractor::Matcher
- Defined in:
- lib/fear/extractor/matcher.rb,
lib/fear/extractor/matcher/and.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.
abstract matcher to inherit from.
Direct Known Subclasses
AnyMatcher, ArrayHeadMatcher, ArrayMatcher, ArraySplatMatcher, EmptyListMatcher, ExtractorMatcher, IdentifierMatcher, And, TypedIdentifierMatcher, ValueMatcher
Defined Under Namespace
Classes: And
Constant Summary collapse
- EMPTY_HASH =
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.
{}.freeze
- EMPTY_ARRAY =
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.
[].freeze
Instance Method Summary collapse
- #and(other) ⇒ Object private
- #call(arg) ⇒ Object private
- #call_or_else(arg) {|arg| ... } ⇒ Object private
-
#failure_reason(other) ⇒ Object
private
Shows why matcher has failed.
-
#initialize(node:, **attributes) ⇒ Matcher
constructor
private
A new instance of Matcher.
Constructor Details
#initialize(node:, **attributes) ⇒ Matcher
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.
Returns a new instance of Matcher.
15 16 17 18 19 |
# File 'lib/fear/extractor/matcher.rb', line 15 def initialize(node:, **attributes) @input = node.input @input_position = node.interval.first super(attributes) end |
Instance Method Details
#and(other) ⇒ Object
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.
28 29 30 |
# File 'lib/fear/extractor/matcher.rb', line 28 def and(other) And.new(self, other) end |
#call(arg) ⇒ Object
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.
24 25 26 |
# File 'lib/fear/extractor/matcher.rb', line 24 def call(arg) call_or_else(arg, &PartialFunction::EMPTY) end |
#call_or_else(arg) {|arg| ... } ⇒ Object
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.
34 35 36 37 38 39 40 |
# File 'lib/fear/extractor/matcher.rb', line 34 def call_or_else(arg) if defined_at?(arg) bindings(arg) else yield arg end end |
#failure_reason(other) ⇒ Object
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.
Shows why matcher has failed. Use it for debugging.
47 48 49 50 51 52 53 |
# File 'lib/fear/extractor/matcher.rb', line 47 def failure_reason(other) if defined_at?(other) Fear.none else Fear.some("Expected `#{other.inspect}` to match:\n#{input}\n#{"~" * input_position}^") end end |