Class: TreeStand::AstModifier

Inherits:
Object
  • Object
show all
Defined in:
lib/tree_stand/ast_modifier.rb

Overview

An experimental class to modify the AST. I 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) ⇒ AstModifier

Returns a new instance of AstModifier.

Parameters:



8
9
10
# File 'lib/tree_stand/ast_modifier.rb', line 8

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:



16
17
18
19
20
21
22
23
# File 'lib/tree_stand/ast_modifier.rb', line 16

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

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