Class: NodeMutation::ReplaceAction

Inherits:
Action
  • Object
show all
Defined in:
lib/node_mutation/action/replace_action.rb

Overview

ReplaceAction to replace child node with code.

Instance Attribute Summary

Attributes inherited from Action

#actions, #end, #start, #type

Instance Method Summary collapse

Methods inherited from Action

#process, #to_struct

Constructor Details

#initialize(node, *selectors, adapter:, with:) ⇒ ReplaceAction

Initailize a ReplaceAction.

Parameters:

  • node (Node)
  • selectors (Array<Symbol|String>)

    used to select child nodes

  • with (String)

    the new code

  • adapter (NodeMutation::Adapter)


11
12
13
14
15
# File 'lib/node_mutation/action/replace_action.rb', line 11

def initialize(node, *selectors, adapter:, with:)
  super(node, with, adapter: adapter)
  @selectors = selectors
  @type = :replace
end

Instance Method Details

#new_codeString

The rewritten source code.

Returns:

  • (String)

    rewritten code.



20
21
22
# File 'lib/node_mutation/action/replace_action.rb', line 20

def new_code
  rewritten_source
end