In Files

  • mrbgems/mruby-enum-chain/mrblib/chain.rb

Parent

Included Modules

Enumerator::Chain

Public Class Methods

new(*args) click to toggle source
 
               # File mrbgems/mruby-enum-chain/mrblib/chain.rb, line 19
def initialize(*args)
  @enums = args.freeze
  @pos = -1
end
            

Public Instance Methods

+(other) click to toggle source
 
               # File mrbgems/mruby-enum-chain/mrblib/chain.rb, line 54
def +(other)
  self.class.new(self, other)
end
            
each(&block) click to toggle source
 
               # File mrbgems/mruby-enum-chain/mrblib/chain.rb, line 24
def each(&block)
  return to_enum unless block

  i = 0
  while i < @enums.size
    @pos = i
    @enums[i].each(&block)
    i += 1
  end

  self
end
            
inspect() click to toggle source
 
               # File mrbgems/mruby-enum-chain/mrblib/chain.rb, line 58
def inspect
  "#<#{self.class}: #{@enums.inspect}>"
end
            
rewind() click to toggle source
 
               # File mrbgems/mruby-enum-chain/mrblib/chain.rb, line 44
def rewind
  while 0 <= @pos && @pos < @enums.size
    e = @enums[@pos]
    e.rewind if e.respond_to?(:rewind)
    @pos -= 1
  end

  self
end
            
size() click to toggle source
 
               # File mrbgems/mruby-enum-chain/mrblib/chain.rb, line 37
def size
  @enums.reduce(0) do |a, e|
    return nil unless e.respond_to?(:size)
    a + e.size
  end
end