Ruby 4.0 リファレンスマニュアル

instance method Thread::Backtrace::Location#to_s

to_s -> StringRuby 2.0.0 から[permalink][rdoc][edit]

self が表すフレームを Kernel?.caller と同じ表現にした文字列を返します。

# 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

# => path/to/foo.rb:5:in 'initialize'
# path/to/foo.rb:9:in 'new'
# path/to/foo.rb:9:in '<main>'