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) { ... } ⇒ GotoScope

Initialize a GotoScope.

Parameters:

Yields:

  • run on the child node



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

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

Instance Method Details

#processObject

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



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

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