class Synvert::Core::Rewriter::PrependAction
PrependAction
to prepend code to the top of node body.
Constants
- DO_LENGTH
Public Instance Methods
begin_pos()
click to toggle source
Begin position to prepend code.
@return [Integer] begin position.
# File lib/synvert/core/rewriter/action/prepend_action.rb, line 11 def begin_pos case @node.type when :block if @node.children[1].children.empty? @node.children[0].loc.expression.end_pos + DO_LENGTH else @node.children[1].loc.expression.end_pos end when :class @node.children[1] ? @node.children[1].loc.expression.end_pos : @node.children[0].loc.expression.end_pos else @node.children.last.loc.expression.end_pos end end
end_pos()
click to toggle source
End position, always same to begin position.
@return [Integer] end position.
# File lib/synvert/core/rewriter/action/prepend_action.rb, line 29 def end_pos begin_pos end
Private Instance Methods
indent(node)
click to toggle source
Indent of the node.
@param node [Parser::AST::Node] @return [String] n times whitesphace
# File lib/synvert/core/rewriter/action/prepend_action.rb, line 39 def indent(node) if %i[block class].include? node.type ' ' * (node.column + DEFAULT_INDENT) else ' ' * node.column end end