Sha256: 0ef7862358b14c7d8083607102797cb7fc98423b203b9f1e9246d2d584bed637

Contents?: true

Size: 796 Bytes

Versions: 7

Compression:

Stored size: 796 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 = 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

7 entries across 7 versions & 1 rubygems

Version Path
synvert-core-0.20.1 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.20.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.19.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.18.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.17.0 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.16.1 lib/synvert/core/rewriter/scope/goto_scope.rb
synvert-core-0.16.0 lib/synvert/core/rewriter/scope/goto_scope.rb