class IRB::Frame - Documentation for Ruby 3.3

# class IRB::Frame

### Constants

CALL_STACK_OFFSET

  Default number of frames offset

INIT_STACK_TIMES

  Default number of stack frames

### Public Class Methods

bottom(n = 0) click to toggle source

Convenience method for `Frame#bottom`

    # File lib/irb/frame.rb, line 61
    def Frame.bottom(n = 0)
      @backtrace.bottom(n)
    end

new() click to toggle source

Creates a new stack frame

    # File lib/irb/frame.rb, line 26
    def initialize
      @frames = [TOPLEVEL_BINDING] * INIT_STACK_TIMES
    end

sender() click to toggle source

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

    # File lib/irb/frame.rb, line 71
    def Frame.sender
      eval "self", @backtrace.top
    end

top(n = 0) click to toggle source

Convenience method for `Frame#top`

    # File lib/irb/frame.rb, line 66
    def Frame.top(n = 0)
      @backtrace.top(n)
    end

### Public Instance Methods

bottom(n = 0) click to toggle source

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.

    # File lib/irb/frame.rb, line 54
    def bottom(n = 0)
      bind = @frames[n]
      fail FrameOverflow unless bind
      bind
    end

top(n = 0) click to toggle source

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.

    # File lib/irb/frame.rb, line 44
    def top(n = 0)
      bind = @frames[-(n + CALL_STACK_OFFSET)]
      fail FrameUnderflow unless bind
      bind
    end

trace_func(event, file, line, id, binding) click to toggle source

Used by `Kernel#set_trace_func` to register each event in the call stack

    # File lib/irb/frame.rb, line 31
    def trace_func(event, file, line, id, binding)
      case event
      when 'call', 'class'
        @frames.push binding
      when 'return', 'end'
        @frames.pop
      end
    end