Created
November 7, 2009 07:44
-
-
Save jcbozonier/228609 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class StringReader | |
| def initialize(string) | |
| @string = string | |
| @current_index = -1 | |
| end | |
| def peek | |
| if end_of_string | |
| return nil | |
| end | |
| @string[@current_index + 1, 1] | |
| end | |
| def read | |
| if end_of_string | |
| raise Exception.new("Tried to read past end of string! Je n'aime pas que!") | |
| end | |
| @current_index += 1 | |
| @string[@current_index, 1] | |
| end | |
| def end_of_string | |
| @current_index == @string.length - 1 | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment