Class: Synvert::Core::Rewriter::ReplaceWithAction
- Defined in:
- lib/synvert/core/rewriter/action/replace_with_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.
9 10 11 |
# File 'lib/synvert/core/rewriter/action/replace_with_action.rb', line 9 def begin_pos @node.loc.expression.begin_pos end |
#end_pos ⇒ Integer
End position of code to replace.
16 17 18 |
# File 'lib/synvert/core/rewriter/action/replace_with_action.rb', line 16 def end_pos @node.loc.expression.end_pos end |
#rewritten_code ⇒ String
The rewritten source code with proper indent.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/synvert/core/rewriter/action/replace_with_action.rb', line 23 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 |