From 4fc1c97489b413417290e4f6713800d913f5df56 Mon Sep 17 00:00:00 2001 From: Rob Gleeson Date: Tue, 10 Jan 2012 04:06:30 +0000 Subject: [PATCH] Refactor edit-command to take advantage of Pry::Method#source. --- lib/pry/extended_commands/user_command_api.rb | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/pry/extended_commands/user_command_api.rb b/lib/pry/extended_commands/user_command_api.rb index d8d9304a..f70876e8 100644 --- a/lib/pry/extended_commands/user_command_api.rb +++ b/lib/pry/extended_commands/user_command_api.rb @@ -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