Class: Iterator

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/iterator.rb

Overview

Indexing

Author: Stefan Rusterholz Contact: [email protected]> Version: 1.0.0 Date: 2007-10-12

About

Similar like Enumarator, enables to create an Enumerable.

Synopsis

x = Iterator.new { |iter| [1,2,3].each { |e| iter.yield(e) } }
p x.map { |e| e*2 }

Defined Under Namespace

Classes: Iteration

Instance Method Summary collapse

Methods included from Enumerable

#join

Constructor Details

#initialize(&iterator) ⇒ Iterator

Determine how to iterate, the block most contain the code that is executed to iterate.



36
37
38
# File 'lib/iterator.rb', line 36

def initialize(&iterator)
	@iterator = iterator
end

Instance Method Details

#each(&block) ⇒ Object

Will iterate as defined in Iterator::new



41
42
43
# File 'lib/iterator.rb', line 41

def each(&block)
	@iterator.call(Iteration.new(&block))
end