Sha256: 41c1180cd4e55a35224ef43c3e9d7d9afa02fce19e61f472b42a7bac6c89a1b4

Contents?: true

Size: 984 Bytes

Versions: 39

Compression:

Stored size: 984 Bytes

Contents

# frozen_string_literal: true

module Synvert::Core
  # Go to and change its scope to a child node.
  class Rewriter::GotoScope < Rewriter::Scope
    # Initialize a GotoScope.
    #
    # @param instance [Synvert::Core::Rewriter::Instance]
    # @param child_node_name [Symbol|String] name of child node
    # @yield run on the child node
    def initialize(instance, child_node_name, &block)
      super(instance, &block)
      @child_node_name = child_node_name
    end

    # Go to a child now, then run the block code on the the child node.
    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
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
synvert-core-1.21.1 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-1.21.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-1.20.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-1.19.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-1.18.1 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-1.18.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-1.17.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-1.16.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-1.15.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-1.14.2 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-1.14.1 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-1.14.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-1.13.1 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-1.13.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-1.12.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-1.11.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-1.10.1 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-1.10.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-1.9.2 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-1.9.1 lib/synvert/core/rewriter/scope/goto_scope.rb