Sha256: 218dd18aac49a12fd0ee7d7e6d165b649257fd25daa94b8f240993a0c50c9235

Contents?: true

Size: 1.2 KB

Versions: 10

Compression:

Stored size: 1.2 KB

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
      if child_node.is_a?(Array)
        child_node.each do |child_child_node|
          @instance.process_with_other_node child_child_node do
            @instance.instance_eval(&@block)
          end
        end
      else
        @instance.process_with_other_node child_node do
          @instance.instance_eval(&@block)
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
synvert-core-1.23.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-1.22.2 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-1.22.1 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-1.22.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-1.21.7 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-1.21.6 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-1.21.5 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-1.21.4 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-1.21.3 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-1.21.2 lib/synvert/core/rewriter/scope/goto_scope.rb