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.
- C
- L
- N
- S
Attributes
[R] | offsets | The list of newline byte offsets in the source code. |
[R] | source | The source code that this source object represents. |
[RW] | start_line | The line number where this source starts. |
Class Public methods
new(source, start_line = 1, offsets = compute_offsets(source)) Link
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 Public methods
character_column(byte_offset) Link
Return the column number in characters for the given byte offset.
character_offset(byte_offset) Link
Return the character offset for the given byte offset.
column(byte_offset) Link
Return the column number for the given byte offset.
line(byte_offset) Link
Binary search through the offsets to find the line number for the given byte offset.
line_start(byte_offset) Link
Return the byte offset of the start of the line corresponding to the given byte offset.