Sha256: d85fea01379b75f7eb6d34c46cf8f5c958a556e4ac0fa80496f05e4f8fdd47d8
Contents?: true
Size: 991 Bytes
Versions: 10
Compression:
Stored size: 991 Bytes
Contents
# frozen_string_literal: true module Synvert::Core # ReplaceWithAction to replace code. class Rewriter::ReplaceWithAction < Rewriter::Action # Begin position of code to replace. # # @return [Integer] begin position. def begin_pos @node.loc.expression.begin_pos end # End position of code to replace. # # @return [Integer] end position. def end_pos @node.loc.expression.end_pos end # The rewritten source code with proper indent. # # @return [String] rewritten code. 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 private # Indent of the node # # @return [String] n times whitesphace def indent ' ' * @node.column end end end
Version data entries
10 entries across 10 versions & 1 rubygems