class Guileless::InputStream

Public Class Methods

new(input) click to toggle source
# File lib/guileless/input_stream.rb, line 3
def initialize(input)
  @buffer = input.chars.to_a
end

Public Instance Methods

discard(count=1) click to toggle source
# File lib/guileless/input_stream.rb, line 19
def discard(count=1)
  count.times { @buffer.shift }
end
empty?() click to toggle source
# File lib/guileless/input_stream.rb, line 11
def empty?
  @buffer.length == 0
end
fetch() click to toggle source
# File lib/guileless/input_stream.rb, line 15
def fetch
  @buffer.shift
end
peek?(patterns) click to toggle source
# File lib/guileless/input_stream.rb, line 27
def peek?(patterns)
  match = false
  Array(patterns).each do |pattern|
    if pattern.kind_of?(Regexp)
      match = true if self.to_s =~ pattern
    elsif pattern.kind_of?(String)
      match = true if self.to_s[0...(pattern.length)] == pattern
    end
  end
  match
end
reinject(char) click to toggle source
# File lib/guileless/input_stream.rb, line 7
def reinject(char)
  @buffer.unshift(char)
end
strip_whitespace() click to toggle source
# File lib/guileless/input_stream.rb, line 23
def strip_whitespace
  @buffer.shift while @buffer.first == "\n"
end
to_s() click to toggle source
# File lib/guileless/input_stream.rb, line 39
def to_s
  @buffer.join
end