diff options
Diffstat (limited to 'lib/irb/frame.rb')
-rw-r--r-- | lib/irb/frame.rb | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/irb/frame.rb b/lib/irb/frame.rb index 8814b47a9d..bcfa3a3140 100644 --- a/lib/irb/frame.rb +++ b/lib/irb/frame.rb @@ -17,13 +17,17 @@ module IRB def_exception :FrameOverflow, "frame overflow" def_exception :FrameUnderflow, "frame underflow" + # Default number of stack frames INIT_STACK_TIMES = 3 + # Default number of frames offset CALL_STACK_OFFSET = 3 + # Creates a new stack frame def initialize @frames = [TOPLEVEL_BINDING] * INIT_STACK_TIMES end + # Used by Kernel#set_trace_func to register each event in the call stack def trace_func(event, file, line, id, binding) case event when 'call', 'class' @@ -33,27 +37,37 @@ module IRB end end + # 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. def top(n = 0) bind = @frames[-(n + CALL_STACK_OFFSET)] Fail FrameUnderflow unless bind bind end + # 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. def bottom(n = 0) bind = @frames[n] Fail FrameOverflow unless bind bind end - # singleton functions + # Convenience method for Frame#bottom def Frame.bottom(n = 0) @backtrace.bottom(n) end + # Convenience method for Frame#top def Frame.top(n = 0) @backtrace.top(n) end + # Returns the binding context of the caller from the last frame initialized def Frame.sender eval "self", @backtrace.top end |