class TDParser::TokenGenerator

Public Class Methods

new(args = nil, &block) click to toggle source
# File lib/tdparser/token_generator.rb, line 3
def initialize(args = nil, &block)
  enumerator = Enumerator.new do |y|
    if args
      args.each { |arg| y << arg }
    else
      block.call(y)
    end
  end
  @enumerator = enumerator

  @buffer = []
end

Public Instance Methods

next() click to toggle source
# File lib/tdparser/token_generator.rb, line 16
def next
  @enumerator.next
end
next?() click to toggle source
# File lib/tdparser/token_generator.rb, line 20
def next?
  @enumerator.peek
  true
rescue StopIteration
  false
end
shift() click to toggle source
# File lib/tdparser/token_generator.rb, line 31
def shift
  if @buffer.empty?
    (self.next if next?)
  else
    @buffer.shift
  end
end
to_a() click to toggle source
# File lib/tdparser/token_generator.rb, line 27
def to_a
  @enumerator.to_a
end
unshift(*token) click to toggle source
# File lib/tdparser/token_generator.rb, line 39
def unshift(*token)
  @buffer.unshift(*token)
end