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.
564 565 566 567 |
# File 'lib/fast.rb', line 564 def initialize(token) super @captures = [] end |
Instance Attribute Details
#captures ⇒ Object (readonly)
Stores nodes that matches with the current expression.
562 563 564 |
# File 'lib/fast.rb', line 562 def captures @captures end |
Instance Method Details
#match?(node) ⇒ Boolean
Append the matching node to #captures if it matches
570 571 572 |
# File 'lib/fast.rb', line 570 def match?(node) @captures << node if super end |
#to_s ⇒ Object
574 575 576 |
# File 'lib/fast.rb', line 574 def to_s "c[#{token}]" end |