Method: Parser::Source::Rewriter#process

Defined in:
lib/parser/source/rewriter.rb

#processString

Deprecated.

Applies all scheduled changes to the source_buffer and returns modified source as a new string.

Returns:

  • (String)

178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/parser/source/rewriter.rb', line 178

def process
  if in_transaction?
    raise "Do not call #{self.class}##{__method__} inside a transaction"
  end

  adjustment = 0
  source     = @source_buffer.source.dup

  @queue.sort.each do |action|
    begin_pos = action.range.begin_pos + adjustment
    end_pos   = begin_pos + action.range.length

    source[begin_pos...end_pos] = action.replacement

    adjustment += (action.replacement.length - action.range.length)
  end

  source
end