Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method · added in Ruby 4.1

Thread::Backtrace::Location#source_range

location.source_range → Ruby::SourceRange

Returns the Ruby::SourceRange for the Ruby expression associated with this backtrace location.

On CRuby, this method re-reads and re-parses the source file to determine the range. File errors encountered while reading the source are propagated. RuntimeError is raised if required source location information is unavailable, or if the source has changed.

RubyVM.keep_script_lines = true can be used to retain source files in memory and avoid re-reading them from the filesystem.

Locations from eval’d code are only available with RubyVM.keep_script_lines = true.

Ruby version changes

  1. 4.1