Permalink
Browse files

version 0.7.1, upgraded dependency on method_source to 0.4.0 so that

accurately returns C source for immediate value instance methods.

* refactored repl into 2 help methods: repl_prologue, repl_epilogue
* added session_target method to Pry instances so can retrieve target
of session for parents, e.g _pry_.parent.session_target
* refactored ls command to use Symbol#to_proc
  • Loading branch information...
1 parent de38710 commit 41d744c07575b01365dc9a2e625051f491f73950 @banister committed Mar 16, 2011
Showing with 42 additions and 23 deletions.
  1. +2 −2 Rakefile
  2. +1 −1 lib/pry/commands.rb
  3. +38 −19 lib/pry/pry_instance.rb
  4. +1 −1 lib/pry/version.rb
View
@@ -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
View
@@ -321,7 +321,7 @@ class Commands < CommandBase
# 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
@@ -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 @@ def exec_hook(hook_name, *args, &block)
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,36 +108,20 @@ def repl(target=TOPLEVEL_BINDING)
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
rep(target)
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
View
@@ -1,3 +1,3 @@
class Pry
- VERSION = "0.7.1"
+ VERSION = "0.7.2"
end

0 comments on commit 41d744c

Please sign in to comment.