From e0224000db8359c1c7b5aa1b9ea9304a583b9255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mon=20ou=C3=AFe?= Date: Sun, 15 May 2011 12:03:16 +0200 Subject: [PATCH] Added a first try to implement _in_ and _out_ arrays in Pry --- lib/pry/history_array.rb | 2 +- lib/pry/pry_instance.rb | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/pry/history_array.rb b/lib/pry/history_array.rb index 2fc7bba8..b6beb179 100644 --- a/lib/pry/history_array.rb +++ b/lib/pry/history_array.rb @@ -84,7 +84,7 @@ class Pry end def inspect - to_a.inspect + "#<#{self.class} size=#{size} first=#{@count - size} max_size=#{max_size}>" end # @return [Integer] Maximum amount of objects in the array diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index 9477e252..e246ceaf 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -34,6 +34,9 @@ class Pry end @command_processor = CommandProcessor.new(self) + + @input_array = HistoryArray.new(100) + @output_array = HistoryArray.new(100) end # Get nesting data. @@ -72,7 +75,10 @@ class Pry # Make sure special locals exist target.eval("_pry_ = ::Pry.active_instance") - target.eval("_ = ::Pry.last_result") + target.eval("_ = ::Pry.last_result") + target.eval("_in_ = ::Pry.active_instance.instance_eval { @input_array }") + target.eval("_out_ = ::Pry.active_instance.instance_eval { @output_array }") + self.session_target = target end @@ -154,6 +160,8 @@ class Pry # save the pry instance to active_instance Pry.active_instance = self target.eval("_pry_ = ::Pry.active_instance") + target.eval("_in_ = ::Pry.active_instance.instance_eval { @input_array }") + target.eval("_out_ = ::Pry.active_instance.instance_eval { @output_array }") @last_result_is_exception = false @@ -191,6 +199,7 @@ class Pry @suppress_output = true if eval_string =~ /;\Z/ || null_input?(val) + @input_array << eval_string eval_string end @@ -251,6 +260,7 @@ class Pry # @param [Binding] target The binding to set `_` on. def set_last_result(result, target) Pry.last_result = result + @output_array << result target.eval("_ = ::Pry.last_result") end