Class: Synvert::Core::Rewriter::ReplaceWithAction
- Defined in:
- lib/synvert/core/rewriter/action.rb
Overview
ReplaceWithAction to replace code.
Instance Method Summary collapse
-
#begin_pos ⇒ Integer
Begin position of code to replace.
-
#end_pos ⇒ Integer
End position of code to replace.
-
#rewritten_code ⇒ String
The rewritten source code with proper indent.
Methods inherited from Action
#<=>, #initialize, #line, #rewritten_source
Constructor Details
This class inherits a constructor from Synvert::Core::Rewriter::Action
Instance Method Details
#begin_pos ⇒ Integer
Begin position of code to replace.
57 58 59 |
# File 'lib/synvert/core/rewriter/action.rb', line 57 def begin_pos @node.loc.expression.begin_pos end |
#end_pos ⇒ Integer
End position of code to replace.
64 65 66 |
# File 'lib/synvert/core/rewriter/action.rb', line 64 def end_pos @node.loc.expression.end_pos end |
#rewritten_code ⇒ String
The rewritten source code with proper indent.
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/synvert/core/rewriter/action.rb', line 71 def rewritten_code if rewritten_source.split("\n").length > 1 new_code = [] rewritten_source.split("\n").each_with_index { |line, index| new_code << (index == 0 ? line : indent(@node) + line) } new_code.join("\n") else rewritten_source end end |