Class: Synvert::Rewriter::ReplaceWithAction

Inherits:
Action
  • Object
show all
Defined in:
lib/synvert/rewriter/action.rb

Overview

ReplaceWithAction to replace code.

Instance Method Summary collapse

Methods inherited from Action

#<=>, #initialize, #line, #rewritten_source

Constructor Details

This class inherits a constructor from Synvert::Rewriter::Action

Instance Method Details

#begin_posInteger

Begin position of code to replace.

Returns:

  • (Integer)

    begin position.



57
58
59
# File 'lib/synvert/rewriter/action.rb', line 57

def begin_pos
  @node.loc.expression.begin_pos
end

#end_posInteger

End position of code to replace.

Returns:

  • (Integer)

    end position.



64
65
66
# File 'lib/synvert/rewriter/action.rb', line 64

def end_pos
  @node.loc.expression.end_pos
end

#rewritten_codeString

The rewritten source code with proper indent.

Returns:

  • (String)

    rewritten code.



71
72
73
74
75
76
77
78
79
# File 'lib/synvert/rewriter/action.rb', line 71

def rewritten_code
  if rewritten_source.split("\n").length > 1
    "\n\n" + rewritten_source.split("\n").map { |line|
      indent(@node) + line
    }.join("\n")
  else
    rewritten_source
  end
end