Refactor edit-command to take advantage of Pry::Method#source.

This commit is contained in:
Rob Gleeson 2012-01-10 04:06:30 +00:00
parent 5679b6fa31
commit 4fc1c97489
1 changed files with 13 additions and 11 deletions

View File

@ -94,24 +94,26 @@ class Pry
end
def edit_temporarily
source_code = @command.block.source
source_code = Pry::Method(block).source
modified_code = nil
temp_file :unlink => false do |f|
temp_file do |f|
f.write(source_code)
f.flush
invoke_editor(f.path, 1)
modified_code = File.read(f.path)
command_set = CommandSet.new do
silence_warnings do
eval(modified_code, binding, f.path, 1)
end
end
@pry.commands.delete(@command.name)
@pry.commands.import(command_set)
end
command_set = CommandSet.new do
silence_warnings do
pry = Pry.new :input => StringIO.new(modified_code)
pry.rep(binding)
end
end
@pry.commands.delete(@command.name)
@pry.commands.import(command_set)
end
end