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.
631 632 633 634 |
# File 'lib/fast.rb', line 631 def initialize(token) super @captures = [] end |
Instance Attribute Details
#captures ⇒ Object (readonly)
Stores nodes that matches with the current expression.
629 630 631 |
# File 'lib/fast.rb', line 629 def captures @captures end |
Instance Method Details
#match?(node) ⇒ Boolean
Append the matching node to #captures if it matches
637 638 639 |
# File 'lib/fast.rb', line 637 def match?(node) @captures << node if super end |
#to_s ⇒ Object
641 642 643 |
# File 'lib/fast.rb', line 641 def to_s "c[#{token}]" end |