Type:
Class

An object representation of a stack frame, initialized by Kernel#caller_locations.

For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# caller_locations.rb
def a(skip)
  caller_locations(skip)
end
def b(skip)
  a(skip)
end
def c(skip)
  b(skip)
end
 
c(0..2).map do |call|
  puts call.to_s
end

Running ruby caller_locations.rb will produce:

1
2
3
caller_locations.rb:2:in `a'
caller_locations.rb:5:in `b'
caller_locations.rb:8:in `c'

Here's another example with a slightly different result:

1
2
3
4
5
6
7
8
9
10
11
# foo.rb
class Foo
  attr_accessor :locations
  def initialize(skip)
    @locations = caller_locations(skip)
  end
end
 
Foo.new(0..2).locations.map do |call|
  puts call.to_s
end

Now run ruby foo.rb and you should see:

1
2
3
init.rb:4:in `initialize'
init.rb:8:in `new'
init.rb:8:in `<main>'
to_s
  • References/Ruby on Rails/Ruby/Classes/Thread/Thread::Backtrace/Thread::Backtrace::Location

to_s() Instance Public methods Returns a

2025-01-10 15:47:30
path
  • References/Ruby on Rails/Ruby/Classes/Thread/Thread::Backtrace/Thread::Backtrace::Location

path() Instance Public methods Returns the file name of this frame.

2025-01-10 15:47:30
absolute_path
  • References/Ruby on Rails/Ruby/Classes/Thread/Thread::Backtrace/Thread::Backtrace::Location

absolute_path() Instance Public methods Returns the full file path of this frame

2025-01-10 15:47:30
label
  • References/Ruby on Rails/Ruby/Classes/Thread/Thread::Backtrace/Thread::Backtrace::Location

label() Instance Public methods Returns the label of this frame.

2025-01-10 15:47:30
inspect
  • References/Ruby on Rails/Ruby/Classes/Thread/Thread::Backtrace/Thread::Backtrace::Location

inspect() Instance Public methods Returns the same as calling inspect

2025-01-10 15:47:30
lineno
  • References/Ruby on Rails/Ruby/Classes/Thread/Thread::Backtrace/Thread::Backtrace::Location

lineno() Instance Public methods Returns the line number of this frame.

2025-01-10 15:47:30
base_label
  • References/Ruby on Rails/Ruby/Classes/Thread/Thread::Backtrace/Thread::Backtrace::Location

base_label() Instance Public methods Returns the base label of this frame.

2025-01-10 15:47:30