Class: Tinybucket::Enumerator
- Inherits:
-
Enumerator
- Object
- Enumerator
- Tinybucket::Enumerator
- Defined in:
- lib/tinybucket/enumerator.rb
Instance Method Summary collapse
-
#initialize(iterator, block) ⇒ Enumerator
constructor
Constructor.
-
#size ⇒ Fixnum, NillClass
Get collection size.
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.
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
#size ⇒ Fixnum, NillClass
Get collection size.
33 34 35 |
# File 'lib/tinybucket/enumerator.rb', line 33 def size @iterator.size end |