mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Manage binding_stack in r() too!
This commit is contained in:
parent
0be747cccb
commit
c3d5469a1a
2 changed files with 8 additions and 6 deletions
|
@ -200,8 +200,6 @@ class Pry
|
||||||
set_last_result(nil, target)
|
set_last_result(nil, target)
|
||||||
|
|
||||||
@input_array << nil # add empty input so _in_ and _out_ match
|
@input_array << nil # add empty input so _in_ and _out_ match
|
||||||
|
|
||||||
binding_stack.push target
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Clean-up after the repl session.
|
# Clean-up after the repl session.
|
||||||
|
@ -209,7 +207,6 @@ class Pry
|
||||||
def repl_epilogue(target)
|
def repl_epilogue(target)
|
||||||
exec_hook :after_session, output, target, self
|
exec_hook :after_session, output, target, self
|
||||||
|
|
||||||
binding_stack.pop
|
|
||||||
Pry.save_history if Pry.config.history.should_save
|
Pry.save_history if Pry.config.history.should_save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -226,7 +223,7 @@ class Pry
|
||||||
|
|
||||||
repl_prologue(target)
|
repl_prologue(target)
|
||||||
|
|
||||||
rep(binding_stack.last)
|
rep(target)
|
||||||
ensure
|
ensure
|
||||||
repl_epilogue(target)
|
repl_epilogue(target)
|
||||||
end
|
end
|
||||||
|
@ -252,7 +249,7 @@ class Pry
|
||||||
break_data = nil
|
break_data = nil
|
||||||
exception = catch(:raise_up) do
|
exception = catch(:raise_up) do
|
||||||
break_data = catch(:breakout) do
|
break_data = catch(:breakout) do
|
||||||
r(binding_stack.last)
|
r(target)
|
||||||
end
|
end
|
||||||
exception = false
|
exception = false
|
||||||
end
|
end
|
||||||
|
@ -272,11 +269,12 @@ class Pry
|
||||||
# @example
|
# @example
|
||||||
# Pry.new.r(Object.new)
|
# Pry.new.r(Object.new)
|
||||||
def r(target=TOPLEVEL_BINDING)
|
def r(target=TOPLEVEL_BINDING)
|
||||||
target = Pry.binding_for(target)
|
binding_stack.push Pry.binding_for(target)
|
||||||
eval_string = ""
|
eval_string = ""
|
||||||
|
|
||||||
loop do
|
loop do
|
||||||
throw(:breakout) if binding_stack.empty?
|
throw(:breakout) if binding_stack.empty?
|
||||||
|
target = binding_stack.last
|
||||||
@suppress_output = false
|
@suppress_output = false
|
||||||
inject_sticky_locals(target)
|
inject_sticky_locals(target)
|
||||||
|
|
||||||
|
@ -325,6 +323,9 @@ class Pry
|
||||||
|
|
||||||
exec_hook :after_read, eval_string, self
|
exec_hook :after_read, eval_string, self
|
||||||
eval_string
|
eval_string
|
||||||
|
|
||||||
|
ensure
|
||||||
|
binding_stack.pop
|
||||||
end
|
end
|
||||||
|
|
||||||
def evaluate_ruby(code, target = binding_stack.last)
|
def evaluate_ruby(code, target = binding_stack.last)
|
||||||
|
|
|
@ -23,6 +23,7 @@ describe "Prompts" do
|
||||||
redirect_pry_io(InputTester.new("def hello", "exit-all")) do
|
redirect_pry_io(InputTester.new("def hello", "exit-all")) do
|
||||||
Pry.start(self, :prompt => proc { |v| config = v })
|
Pry.start(self, :prompt => proc { |v| config = v })
|
||||||
end
|
end
|
||||||
|
|
||||||
config.eval_string.should =~ /def hello/
|
config.eval_string.should =~ /def hello/
|
||||||
config.nesting_level.should == 0
|
config.nesting_level.should == 0
|
||||||
config.expr_number.should == 1
|
config.expr_number.should == 1
|
||||||
|
|
Loading…
Reference in a new issue