Class: IRB::Frame
Defined Under Namespace
Classes: FrameOverflow, FrameUnderflow
Constant Summary collapse
- INIT_STACK_TIMES =
Default number of stack frames
3
- CALL_STACK_OFFSET =
Default number of frames offset
3
Class Method Summary collapse
-
.bottom(n = 0) ⇒ Object
Convenience method for Frame#bottom.
-
.sender ⇒ Object
Returns the binding context of the caller from the last frame initialized.
-
.top(n = 0) ⇒ Object
Convenience method for Frame#top.
Instance Method Summary collapse
-
#bottom(n = 0) ⇒ Object
Returns the
n
number of frames on the call stack from the first frame initialized. -
#initialize ⇒ Frame
constructor
Creates a new stack frame.
-
#top(n = 0) ⇒ Object
Returns the
n
number of frames on the call stack from the last frame initialized. -
#trace_func(event, file, line, id, binding) ⇒ Object
Used by Kernel#set_trace_func to register each event in the call stack.
Constructor Details
#initialize ⇒ Frame
Creates a new stack frame
32 33 34 |
# File 'lib/irb/frame.rb', line 32 def initialize @frames = [TOPLEVEL_BINDING] * INIT_STACK_TIMES end |
Class Method Details
.bottom(n = 0) ⇒ Object
Convenience method for Frame#bottom
67 68 69 |
# File 'lib/irb/frame.rb', line 67 def Frame.bottom(n = 0) @backtrace.bottom(n) end |
Instance Method Details
#bottom(n = 0) ⇒ Object
Returns the n
number of frames on the call stack from the first frame initialized.
Raises FrameOverflow if there are no frames in the given stack range.
60 61 62 63 64 |
# File 'lib/irb/frame.rb', line 60 def bottom(n = 0) bind = @frames[n] fail FrameOverflow unless bind bind end |
#top(n = 0) ⇒ Object
Returns the n
number of frames on the call stack from the last frame initialized.
Raises FrameUnderflow if there are no frames in the given stack range.
50 51 52 53 54 |
# File 'lib/irb/frame.rb', line 50 def top(n = 0) bind = @frames[-(n + CALL_STACK_OFFSET)] fail FrameUnderflow unless bind bind end |
#trace_func(event, file, line, id, binding) ⇒ Object
Used by Kernel#set_trace_func to register each event in the call stack
37 38 39 40 41 42 43 44 |
# File 'lib/irb/frame.rb', line 37 def trace_func(event, file, line, id, binding) case event when 'call', 'class' @frames.push binding when 'return', 'end' @frames.pop end end |