Class: Synvert::Rewriter::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/synvert/rewriter/scope.rb

Instance Method Summary collapse

Constructor Details

#initialize(instance, options, &block) ⇒ Scope

Returns a new instance of Scope.



5
6
7
8
9
# File 'lib/synvert/rewriter/scope.rb', line 5

def initialize(instance, options, &block)
  @instance = instance
  @options = options
  @block = block
end

Instance Method Details

#processObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/synvert/rewriter/scope.rb', line 11

def process
  current_node = @instance.current_node
  return unless current_node
  process_with_node current_node do
    matching_nodes = []
    matching_nodes << current_node if current_node.match? @instance, @options
    current_node.recursive_children do |child_node|
      matching_nodes << child_node if child_node.match? @instance, @options
    end
    matching_nodes.each do |matching_node|
      process_with_node matching_node do
        @instance.instance_eval &@block
      end
    end
  end
end