Class: IRB::Frame

Inherits:
Object show all
Extended by:
Exception2MessageMapper
Defined in:
lib/irb/frame.rb

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

Instance Method Summary collapse

Constructor Details

#initializeFrame

Creates a new stack frame



27
28
29
# File 'lib/irb/frame.rb', line 27

def initialize
  @frames = [TOPLEVEL_BINDING] * INIT_STACK_TIMES
end

Class Method Details

.bottom(n = 0) ⇒ Object

Convenience method for Frame#bottom



62
63
64
# File 'lib/irb/frame.rb', line 62

def Frame.bottom(n = 0)
  @backtrace.bottom(n)
end

.senderObject

Returns the binding context of the caller from the last frame initialized



72
73
74
# File 'lib/irb/frame.rb', line 72

def Frame.sender
  eval "self", @backtrace.top
end

.top(n = 0) ⇒ Object

Convenience method for Frame#top



67
68
69
# File 'lib/irb/frame.rb', line 67

def Frame.top(n = 0)
  @backtrace.top(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.



55
56
57
58
59
# File 'lib/irb/frame.rb', line 55

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.



45
46
47
48
49
# File 'lib/irb/frame.rb', line 45

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



32
33
34
35
36
37
38
39
# File 'lib/irb/frame.rb', line 32

def trace_func(event, file, line, id, binding)
  case event
  when 'call', 'class'
    @frames.push binding
  when 'return', 'end'
    @frames.pop
  end
end