1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

fixed formatting, refactored and cleaned up some code

This commit is contained in:
John Mair 2010-12-12 10:53:14 +13:00
parent 1d271ba47b
commit 3542106257
2 changed files with 19 additions and 10 deletions

View file

@ -56,7 +56,7 @@ module Pry
# Make sure _ exists
target.eval("_ = Pry.last_result")
nesting_level_breakout = catch(:breakout) do
break_level = catch(:breakout) do
@nesting << [@nesting.size, target_self]
loop do
rep(target)
@ -67,8 +67,8 @@ module Pry
output.session_end(target_self)
# we only enter here if :breakout has been thrown
if nesting_level_breakout
throw :breakout, nesting_level_breakout if nesting_level != nesting_level_breakout
if break_level && nesting_level != break_level
throw :breakout, break_level
end
target_self
@ -132,14 +132,19 @@ module Pry
output.exit
throw(:breakout, nesting.level)
when /jump_to\s*(\d*)/
nesting_level_breakout = ($~.captures).first.to_i
output.jump_to(nesting_level_breakout)
break_level = ($~.captures).first.to_i
output.jump_to(break_level)
if nesting_level_breakout < 0 || nesting_level_breakout >= nesting.level
output.error_invalid_nest_level(nesting_level_breakout, nesting.level - 1)
case break_level
when nesting.level
output.warn_already_at_level(nesting.level)
eval_string.clear
when (0...nesting.level)
throw(:breakout, break_level + 1)
else
throw(:breakout, nesting_level_breakout + 1)
output.err_invalid_nest_level(break_level,
nesting.level - 1)
eval_string.clear
end
end
end
@ -176,7 +181,7 @@ module Pry
module ObjectExtensions
def pry(target=self)
Pry.start(Pry.binding_for(target))
Pry.start(target)
end
end
end

View file

@ -56,7 +56,11 @@ module Pry
puts "Last result: #{Pry.last_result.inspect}"
end
def error_invalid_nest_level(nest_level, max_nest_level)
def warn_already_at_level(nesting_level)
puts "Already at nesting level #{nesting_level}"
end
def err_invalid_nest_level(nest_level, max_nest_level)
puts "Invalid nest level. Must be between 0 and #{max_nest_level}. Got #{nest_level}."
end