Class: Fast::Capture
Overview
Capture some expression while searching for it.
The captures behaves exactly like Fast::Find and the only difference is that when it #match? stores #captures for future usage.
You can capture stuff in multiple levels and build expressions that reference captures with Fast::FindWithCapture.
Instance Attribute Summary collapse
-
#captures ⇒ Object
readonly
Stores nodes that matches with the current expression.
Attributes inherited from Find
Instance Method Summary collapse
-
#initialize(token) ⇒ Capture
constructor
A new instance of Capture.
-
#match?(node) ⇒ Boolean
Append the matching node to #captures if it matches.
- #to_s ⇒ Object
Methods inherited from Find
#==, #compare_symbol_or_head, #debug, #debug_match_recursive, #match_recursive
Constructor Details
#initialize(token) ⇒ Capture
Returns a new instance of Capture.
534 535 536 537 |
# File 'lib/fast.rb', line 534 def initialize(token) super @captures = [] end |
Instance Attribute Details
#captures ⇒ Object (readonly)
Stores nodes that matches with the current expression.
532 533 534 |
# File 'lib/fast.rb', line 532 def captures @captures end |
Instance Method Details
#match?(node) ⇒ Boolean
Append the matching node to #captures if it matches
540 541 542 |
# File 'lib/fast.rb', line 540 def match?(node) @captures << node if super end |
#to_s ⇒ Object
544 545 546 |
# File 'lib/fast.rb', line 544 def to_s "c[#{token}]" end |