Sha256: 97d5102faab5fb9a9deafa334af34ff01aebac7342797a4c9e71b859ebcb99ae

Contents?: true

Size: 972 Bytes

Versions: 21

Compression:

Stored size: 972 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 scope
    #
    # @param instance [Synvert::Core::Rewriter::Instance]
    # @param child_node_name [Symbol|string]
    # @param block [Block]
    def initialize(instance, child_node_name, &block)
      @instance = instance
      @child_node_name = child_node_name
      @block = block
    end

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

21 entries across 21 versions & 1 rubygems

Version Path
synvert-core-0.63.1 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.63.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.62.1 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.62.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.61.2 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.61.1 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.61.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.60.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.59.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.58.3 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.58.2 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.58.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.57.1 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.57.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.56.1 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.56.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.55.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.54.3 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.54.2 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.54.1 lib/synvert/core/rewriter/scope/goto_scope.rb