Class: Fast::FindWithCapture
Overview
Allow use previous captures while searching in the AST. Use ‘\1` to point the match to the first captured element or sequential numbers considering the order of the captures.
Instance Attribute Summary collapse
-
#previous_captures ⇒ Object
writeonly
Sets the attribute previous_captures.
Attributes inherited from Find
Instance Method Summary collapse
-
#initialize(token) ⇒ FindWithCapture
constructor
A new instance of FindWithCapture.
- #match?(node) ⇒ Boolean
- #to_s ⇒ Object
Methods inherited from Find
#==, #compare_symbol_or_head, #debug, #debug_match_recursive, #match_recursive
Constructor Details
#initialize(token) ⇒ FindWithCapture
Returns a new instance of FindWithCapture.
432 433 434 435 436 437 |
# File 'lib/fast.rb', line 432 def initialize(token) token = token.token if token.respond_to?(:token) raise 'You must use captures!' unless token @capture_index = token.to_i end |
Instance Attribute Details
#previous_captures=(value) ⇒ Object (writeonly)
Sets the attribute previous_captures
430 431 432 |
# File 'lib/fast.rb', line 430 def previous_captures=(value) @previous_captures = value end |
Instance Method Details
#match?(node) ⇒ Boolean
439 440 441 |
# File 'lib/fast.rb', line 439 def match?(node) node == @previous_captures[@capture_index - 1] end |
#to_s ⇒ Object
443 444 445 |
# File 'lib/fast.rb', line 443 def to_s "fc[\\#{@capture_index}]" end |