Class: Synvert::Core::Rewriter::GotoScope

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

Overview

Go to and change its scope to a child node.

Instance Method Summary collapse

Constructor Details

#initialize(instance, child_node_name, &block) ⇒ GotoScope

Initialize a scope

Parameters:



11
12
13
14
15
# File 'lib/synvert/core/rewriter/scope/goto_scope.rb', line 11

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

Instance Method Details

#processObject

Go to a child now, then run the block code with the the child node.



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/synvert/core/rewriter/scope/goto_scope.rb', line 18

def process
  current_node = @instance.current_node
  return unless current_node

  child_node = current_node
  @child_node_name.to_s.split('.').each do |child_node_name|
    child_node = child_node_name.is_a?(Parser::AST::Node) ? child_node_name : child_node.send(child_node_name)
  end
  @instance.process_with_other_node child_node do
    @instance.instance_eval(&@block)
  end
end