Represents a character position in source code.
It's a value object - it can't be modified.
A re-usable empty position
# File lib/rkelly/char_pos.rb, line 9 def initialize(line, char, index) @line = line @char = char @index = index end
Creates a new character position that's a given string away from this one.
# File lib/rkelly/char_pos.rb, line 17 def next(string) if string.include?("\n") lines = string.split(/\n/, -1) CharPos.new(@line + lines.length - 1, lines.last.length, @index + string.length) else CharPos.new(@line, @char + string.length, @index + string.length) end end
# File lib/rkelly/char_pos.rb, line 26 def to_s "{line:#{@line} char:#{@char} (#{@index})}" end