class RKelly::CharPos
Represents a character position in source code.
It's a value object - it can't be modified.
Constants
- EMPTY
A re-usable empty position
Attributes
char[R]
index[R]
line[R]
Public Class Methods
new(line, char, index)
click to toggle source
# File lib/rkelly/char_pos.rb, line 10 def initialize(line, char, index) @line = line @char = char @index = index end
Public Instance Methods
next(string)
click to toggle source
Creates a new character position that's a given string away from this one.
# File lib/rkelly/char_pos.rb, line 18 def next(string) if !string CharPos.new(@line, @char, @index) elsif string.include?("\n") lines = string.split("\n", -1) CharPos.new(@line + lines.length - 1, lines.last.length, @index + string.length) else length = string.length CharPos.new(@line, @char + length, @index + length) end end
to_s()
click to toggle source
# File lib/rkelly/char_pos.rb, line 30 def to_s "{line:#{@line} char:#{@char} (#{@index})}" end
Also aliased as: inspect