Class: Ast::Merge::SectionTyping::CallableClassifier
- Inherits:
-
Classifier
- Object
- Classifier
- Ast::Merge::SectionTyping::CallableClassifier
- Defined in:
- lib/ast/merge/section_typing.rb
Overview
A classifier that uses a callable (proc/lambda) for classification.
This allows defining classifiers without creating a subclass.
Instance Attribute Summary collapse
-
#callable ⇒ #call
readonly
The callable used for classification.
Instance Method Summary collapse
-
#classify(node) ⇒ TypedSection?
Classify using the callable.
-
#initialize(callable) ⇒ CallableClassifier
constructor
Initialize with a callable.
Methods inherited from Classifier
Constructor Details
#initialize(callable) ⇒ CallableClassifier
Initialize with a callable.
177 178 179 |
# File 'lib/ast/merge/section_typing.rb', line 177 def initialize(callable) @callable = callable end |
Instance Attribute Details
#callable ⇒ #call (readonly)
Returns The callable used for classification.
172 173 174 |
# File 'lib/ast/merge/section_typing.rb', line 172 def callable @callable end |
Instance Method Details
#classify(node) ⇒ TypedSection?
Classify using the callable.
185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/ast/merge/section_typing.rb', line 185 def classify(node) result = callable.call(node) return if result.nil? # Allow callable to return a Hash and convert to TypedSection if result.is_a?(Hash) TypedSection.new(**result) else result end end |