summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Rakefile4
-rw-r--r--lib/pry/commands.rb2
-rw-r--r--lib/pry/pry_instance.rb57
-rw-r--r--lib/pry/version.rb2
4 files changed, 42 insertions, 23 deletions
diff --git a/Rakefile b/Rakefile
index 1be55ee1..47e50afc 100644
--- a/Rakefile
+++ b/Rakefile
@@ -47,7 +47,7 @@ end
namespace :ruby do
spec = Gem::Specification.new do |s|
apply_spec_defaults(s)
- s.add_dependency("method_source",">=0.3.4")
+ s.add_dependency("method_source",">=0.4.0")
s.platform = Gem::Platform::RUBY
end
@@ -61,7 +61,7 @@ end
namespace v do
spec = Gem::Specification.new do |s|
apply_spec_defaults(s)
- s.add_dependency("method_source",">=0.3.4")
+ s.add_dependency("method_source",">=0.4.0")
s.add_dependency("win32console", ">=1.3.0")
s.platform = "i386-#{v}"
end
diff --git a/lib/pry/commands.rb b/lib/pry/commands.rb
index 3fd45861..02958f09 100644
--- a/lib/pry/commands.rb
+++ b/lib/pry/commands.rb
@@ -321,7 +321,7 @@ Shows local and instance variables by default.
# plain
else
- list = info.values.sort_by { |v| v.last }.map { |v| v.first }.inject(&:+)
+ list = info.values.sort_by(&:last).map(&:first).inject(&:+)
list.uniq! if list
if Pry.color
output.puts CodeRay.scan(Pry.view(list), :ruby).term
diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb
index e9e8183a..24194961 100644
--- a/lib/pry/pry_instance.rb
+++ b/lib/pry/pry_instance.rb
@@ -6,6 +6,11 @@ class Pry
attr_accessor *CONFIG_OPTIONS
+ # Returns the target binding for the session. Note that altering this
+ # attribute will not change the target binding.
+ # @return [Binding] The target object for the session
+ attr_accessor :session_target
+
# Create a new `Pry` object.
# @param [Hash] options The optional configuration parameters.
# @option options [#readline] :input The object to use for input.
@@ -61,6 +66,36 @@ class Pry
hooks[hook_name].call(*args, &block) if hooks[hook_name]
end
+ # Initialize the repl session.
+ # @param [Binding] target The target binding for the session.
+ def repl_prologue(target)
+ exec_hook :before_session, output, target
+ Pry.active_instance = self
+
+ # Make sure special locals exist
+ target.eval("_pry_ = Pry.active_instance")
+ target.eval("_ = Pry.last_result")
+ self.session_target = target
+ end
+
+ # Clean-up after the repl session.
+ # @param [Binding] target The target binding for the session.
+ # @return [Object] The return value of the repl session (if one exists).
+ def repl_epilogue(target, nesting_level, break_data)
+ nesting.pop
+ exec_hook :after_session, output, target
+
+ # If break_data is an array, then the last element is the return value
+ break_level, return_value = Array(break_data)
+
+ # keep throwing until we reach the desired nesting level
+ if nesting_level != break_level
+ throw :breakout, break_data
+ end
+
+ return_value
+ end
+
# Start a read-eval-print-loop.
# If no parameter is given, default to top-level (main).
# @param [Object, Binding] target The receiver of the Pry session
@@ -73,18 +108,12 @@ class Pry
target = Pry.binding_for(target)
target_self = target.eval('self')
- exec_hook :before_session, output, target
-
+ repl_prologue(target)
+
# cannot rely on nesting.level as
# nesting.level changes with new sessions
nesting_level = nesting.size
- Pry.active_instance = self
-
- # Make sure special locals exist
- target.eval("_pry_ = Pry.active_instance")
- target.eval("_ = Pry.last_result")
-
break_data = catch(:breakout) do
nesting.push [nesting.size, target_self, self]
loop do
@@ -92,17 +121,7 @@ class Pry
end
end
- nesting.pop
-
- exec_hook :after_session, output, target
-
- # If break_data is an array, then the last element is the return value
- break_level, return_value = Array(break_data)
-
- # keep throwing until we reach the desired nesting level
- if nesting_level != break_level
- throw :breakout, break_data
- end
+ return_value = repl_epilogue(target, nesting_level, break_data)
# if one was provided, return the return value
return return_value if return_value
diff --git a/lib/pry/version.rb b/lib/pry/version.rb
index cbc759c2..75ab551f 100644
--- a/lib/pry/version.rb
+++ b/lib/pry/version.rb
@@ -1,3 +1,3 @@
class Pry
- VERSION = "0.7.1"
+ VERSION = "0.7.2"
end