blob: eca7a9888ab7c4c35fb9b2703b13f6f0d56409ff (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# frozen_string_literal: true
class Pry
class Command
class 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_instance.binding_stack.size - 1
max_nest_level = nesting_level - 1
case break_level
when nesting_level
output.puts "Already at nesting level #{nesting_level}"
when 0..max_nest_level
pry_instance.binding_stack = pry_instance.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
end
|