diff options
author | zzak <zzak@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-12-21 05:45:50 +0000 |
---|---|---|
committer | zzak <zzak@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-12-21 05:45:50 +0000 |
commit | 7e9eb32669348b7e0a5775c8e0fc9566be11fc31 (patch) | |
tree | 96be4fc975e7afab8dbf4c85e04d552760dab34c /lib/irb/frame.rb | |
parent | 4f7a6aafa57bf57ce4b0b5e323548f0a6385d527 (diff) | |
download | ruby-7e9eb32669348b7e0a5775c8e0fc9566be11fc31.tar.gz |
* lib/irb.rb, lib/irb/*: Documentation for IRB
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
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 |