module Rewriter

Constants

VERSION

Public Class Methods

rewrite(path) click to toggle source
# File lib/rewriter.rb, line 8
def rewrite(path)
  with_file(path) do |source|
    ast, comments = Parser::CurrentRuby.parse_with_comments(source)
    Unparser.unparse(ast, comments)
  end
end
with_file(path) { |original| ... } click to toggle source
# File lib/rewriter.rb, line 15
def with_file(path)
  original = File.read(path)
  rewritten = yield(original)
  
  temp_path = "#{path}.rewritten"
  ::File.open(temp_path, 'w') do |temp_file|
    temp_file.write(rewritten)
  end
  
  ::File.rename(temp_path, path)
end