Class: SyntaxTree::MultiByteString
- Inherits:
-
Object
- Object
- SyntaxTree::MultiByteString
- Defined in:
- lib/syntax_tree.rb
Overview
Represents a line in the source. If this class is being used, it means that there are characters in the string that are multi-byte, so we will build up an array of indices, such that array will be equal to the index of the character within the string.
Instance Method Summary collapse
- #[](byteindex) ⇒ Object
-
#initialize(start, line) ⇒ MultiByteString
constructor
A new instance of MultiByteString.
Constructor Details
#initialize(start, line) ⇒ MultiByteString
Returns a new instance of MultiByteString.
43 44 45 46 47 48 49 |
# File 'lib/syntax_tree.rb', line 43 def initialize(start, line) @indices = [] line.each_char.with_index(start) do |char, index| char.bytesize.times { @indices << index } end end |
Instance Method Details
#[](byteindex) ⇒ Object
51 52 53 |
# File 'lib/syntax_tree.rb', line 51 def [](byteindex) @indices[byteindex] end |