Class: NodeMutation::ReplaceWithAction
- Defined in:
- lib/node_mutation/action/replace_with_action.rb
Overview
ReplaceWithAction to replace code.
Instance Attribute Summary
Attributes inherited from Action
Instance Method Summary collapse
-
#initialize(node, code, adapter:) ⇒ ReplaceWithAction
constructor
Initailize a ReplaceWithAction.
-
#new_code ⇒ String
The rewritten source code with proper indent.
Methods inherited from Action
Constructor Details
#initialize(node, code, adapter:) ⇒ ReplaceWithAction
Initailize a ReplaceWithAction.
10 11 12 13 |
# File 'lib/node_mutation/action/replace_with_action.rb', line 10 def initialize(node, code, adapter:) super(node, code, adapter: adapter) @type = :replace end |
Instance Method Details
#new_code ⇒ String
The rewritten source code with proper indent.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/node_mutation/action/replace_with_action.rb', line 18 def new_code if rewritten_source.include?("\n") new_code = [] rewritten_source.split("\n").each_with_index do |line, index| new_code << (index == 0 ? line : indent + line) end new_code.join("\n") else rewritten_source end end |