This represents a source of Ruby code that has been parsed. It is used in conjunction with locations to allow them to resolve line numbers and source ranges.

Attributes
Read

The source code that this source object represents.

Read & Write

The line number where this source starts.

Read

The list of newline byte offsets in the source code.

Class Methods

Create a new source object with the given source code and newline byte offsets. If no newline byte offsets are given, they will be computed from the source code.

Instance Methods

Return the column number in characters for the given byte offset.

Return the character offset for the given byte offset.

Return the column number for the given byte offset.

Find all of the newlines in the source code and return their byte offsets from the start of the string an array.

Binary search through the offsets to find the line number for the given byte offset.

Binary search through the offsets to find the line number for the given byte offset.

Return the byte offset of the start of the line corresponding to the given byte offset.

Perform a byteslice on the source code using the given byte offset and byte length.