Class: TreeStand::AstModifier

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/tree_stand/ast_modifier.rb

Overview

An experimental class to modify the AST. It re-runs the query on the modified document every loop to ensure that the match is still valid.

See Also:

Instance Method Summary collapse

Constructor Details

#initialize(tree) ⇒ void

Parameters:



13
14
15
# File 'lib/tree_stand/ast_modifier.rb', line 13

def initialize(tree)
  @tree = tree
end

Instance Method Details

#on_match(query) {|self, match| ... } ⇒ void

This method returns an undefined value.

Parameters:

  • query (String)

Yield Parameters:

  • self (self)
  • match (TreeStand::Match)


21
22
23
24
25
26
27
28
# File 'lib/tree_stand/ast_modifier.rb', line 21

def on_match(query)
  matches = @tree.query(query)

  while !matches.empty?
    yield self, matches.first
    matches = @tree.query(query)
  end
end