Sha256: 25ce89531cdb66c57d15dbeae0fa9fcad151c2b0c6c2d29d44e093b50bf270de

Contents?: true

Size: 861 Bytes

Versions: 14

Compression:

Stored size: 861 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 [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 = @child_node_name.is_a?(Parser::AST::Node) ? @child_node_name : current_node.send(@child_node_name)
      @instance.process_with_other_node child_node do
        @instance.instance_eval(&@block)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
synvert-core-0.29.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.28.1 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.28.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.27.4 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.27.3 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.27.2 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.27.1 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.27.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.26.1 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.26.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.25.1 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.25.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.24.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.23.0 lib/synvert/core/rewriter/scope/goto_scope.rb