The
IRB::Frame
class represents the interpreter's stack and allows
easy access to the
Binding
environment in effect at different
stack levels.
|
IRB::Frame.top(n = 0)
|
Returns a Binding
for the nth context from the top. The 0th context is
topmost,
most recent frame. |
IRB::Frame.bottom(n = 0)
|
Returns a Binding for the
nth context from the bottom. The 0th context is the
bottommost, initial frame. |
IRB::Frame.sender
|
Returns the object (the sender)
that invoked the current method. |
|
You can use this facility, for instance, to examine local variables
from the method that called the current method:
require 'irb/frame'
def outie
b = IRB::Frame.top(1)
eval "p my_local", b
end
def innie
my_local = 102.7
outie
end
innie
|
produces:
Note that this doesn't work with multithreaded programs.