Class: Tinybucket::Enumerator

Inherits:
Enumerator
  • Object
show all
Defined in:
lib/tinybucket/enumerator.rb

Instance Method Summary collapse

Constructor Details

#initialize(iterator, block) ⇒ Enumerator

Note:

This method return Lazy Enumerator if run on ruby 2.0.0 later.

Constructor

This method create a enumerator to enumerate each items of iterator.

Parameters:

  • iterator (Tinybucket::Iterator)

    iterator instance.

  • block (Proc)

    a proc object to handle each item.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/tinybucket/enumerator.rb', line 13

def initialize(iterator, block)
  @iterator = iterator
  @block = block

  super() do |y|
    loop do
      v = @iterator.next
      m = @block ? @block.call(v) : v
      y.yield(m)
    end
  end

  lazy if lazy_enumerable?
end

Instance Method Details

#sizeFixnum, NillClass

Get collection size.

Returns:

  • (Fixnum, NillClass)

    collection size.

See Also:



33
34
35
# File 'lib/tinybucket/enumerator.rb', line 33

def size
  @iterator.size
end