class Ruby::SourceRange

An object representing the source-code range for a Ruby callable.

Source ranges are returned by Proc#source_range, Method#source_range, and UnboundMethod#source_range. They include the source path, absolute path when available, start line, start byte column, end line, and end byte column.

The primary purpose of this class is to implement Prism.find precisely and cleanly on all Ruby implementations, in a way which does not depend on implementation details like node_id. For that we need the start/end line/column and the absolute_path, which is exactly what this class provides.

The user of Prism.find can then tweak the result as desired to, for example, include heredocs as mentioned in Ruby::SourceRange#end_line. Or for Proc#source_range to include the method to which the block is passed.

Note that the returned source range is not always an evaluable fragment by itself, notably because heredocs can go beyond the end of the method and for blocks because the range starts at ‘{`/do.