class ZombieKiller

The main class called from the CLI

Constants

VERSION

Attributes

eager[R]

@return [Boolean] use the EagerRewriter

Public Class Methods

new(eager: false) click to toggle source
# File lib/zombie_killer/killer.rb, line 14
def initialize(eager: false)
  @eager = eager
end

Public Instance Methods

kill(code, filename = "(inline code)", unsafe: false)
Alias for: kill_string
kill_file(filename, new_filename, unsafe: false) click to toggle source

@param new_filename may be the same as filename

# File lib/zombie_killer/killer.rb, line 39
def kill_file(filename, new_filename, unsafe: false)
  new_string = kill_string(File.read(filename), filename, unsafe: unsafe)

  File.write(new_filename, new_string)
rescue
  puts "While processing #{filename}"
  raise
end
kill_string(code, filename = "(inline code)", unsafe: false) click to toggle source

@param code [String] @param filename [String] @returns new string

# File lib/zombie_killer/killer.rb, line 21
def kill_string(code, filename = "(inline code)", unsafe: false)
  fixed_point(code) do |c|
    parser   = Parser::CurrentRuby.new
    rewriter = eager ? EagerRewriter.new : ZombieKillerRewriter.new(unsafe: unsafe)
    buffer   = Parser::Source::Buffer.new(filename)
    buffer.source = c
    ast = parser.parse(buffer)
    if ast
      rewriter.rewrite(buffer, ast)
    else
      puts "Parse error for '#{filename}', returning it unchanged"
      return code
    end
  end
end
Also aliased as: kill

Private Instance Methods

fixed_point(x, &lambda_x) click to toggle source
# File lib/zombie_killer/killer.rb, line 50
def fixed_point(x, &lambda_x)
  loop do
    y = lambda_x.call(x)
    return y if y == x
    x = y
  end
end