Class: Synvert::Core::Rewriter::ReplaceWithAction
- Defined in:
- lib/synvert/core/rewriter/action/replace_with_action.rb
Overview
ReplaceWithAction to replace code.
Constant Summary
Constants inherited from Action
Instance Attribute Summary
Attributes inherited from Action
Instance Method Summary collapse
- #calculate_position ⇒ Object
-
#rewritten_code ⇒ String
The rewritten source code with proper indent.
Methods inherited from Action
Constructor Details
This class inherits a constructor from Synvert::Core::Rewriter::Action
Instance Method Details
#calculate_position ⇒ Object
6 7 8 9 |
# File 'lib/synvert/core/rewriter/action/replace_with_action.rb', line 6 def calculate_position @begin_pos = @node.loc.expression.begin_pos @end_pos = @node.loc.expression.end_pos end |
#rewritten_code ⇒ String
The rewritten source code with proper indent.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/synvert/core/rewriter/action/replace_with_action.rb', line 14 def rewritten_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 |