1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00
pry--pry/lib/pry/commands/jump_to.rb
Josh Cheek bf24df0cf1 Refactor jump_to and spec
Update jump_to command's spec to RSpec 3 (https://github.com/pry/pry/issues/1294)
Perform some refactorings along the way.
2014-09-01 02:41:43 -06:00

25 lines
851 B
Ruby

class Pry
class Command::JumpTo < Pry::ClassCommand
match 'jump-to'
group 'Navigating Pry'
description 'Jump to a binding further up the stack.'
banner <<-'BANNER'
Jump to a binding further up the stack, popping all bindings below.
BANNER
def process(break_level)
break_level = break_level.to_i
nesting_level = _pry_.binding_stack.size - 1
max_nest_level = nesting_level - 1
case break_level
when nesting_level then output.puts "Already at nesting level #{nesting_level}"
when (0..max_nest_level) then _pry_.binding_stack = _pry_.binding_stack[0..break_level]
else output.puts "Invalid nest level. Must be between 0 and #{max_nest_level}. Got #{break_level}."
end
end
end
Pry::Commands.add_command(Pry::Command::JumpTo)
end