mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
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
This commit is contained in:
parent
de3871001f
commit
41d744c075
4 changed files with 42 additions and 23 deletions
4
Rakefile
4
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
class Pry
|
||||
VERSION = "0.7.1"
|
||||
VERSION = "0.7.2"
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue