struct CharReader

Overview

A CharReader allows iterating a String by Chars.

As soon as you instantiate a CharReader it will decode the first char in the String, which can be accesed by invoking #current_char. At this point #pos, the current position in the string, will equal zero. Successive calls to #next_char return the next chars in the string, advancing #pos.

Note that the null character '\0' will be returned in #current_char when the end is reached (as well as when the string is empty). Thus, #has_next? will return false only when #pos is equal to the string's length, in which case #current_char will always be '\0'.

Superclass hierarchy

Object
Value
Struct
CharReader

Included Modules

Enumerable(Char)

Defined in:

Class Method Summary

Instance Method Summary

Class Method Detail

def self.new(string)

Instance Method Detail

def current_char

def current_char_width

def each(&block)

def has_next?

def next_char

def peek_next_char

def pos

def pos=(pos)

def string