Skip to content

Instantly share code, notes, and snippets.

@jcbozonier
Created November 7, 2009 07:44
Show Gist options
  • Select an option

  • Save jcbozonier/228609 to your computer and use it in GitHub Desktop.

Select an option

Save jcbozonier/228609 to your computer and use it in GitHub Desktop.
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