each(ubound = nil, generator = EratosthenesGenerator.new, &block) public

Iterates the given block over all prime numbers.



Optional. An arbitrary positive number. The upper bound of enumeration. The method enumerates prime numbers infinitely if ubound is nil.


Optional. An implementation of pseudo-prime generator.

Return value

An evaluated value of the given block at the last time. Or an enumerator which is compatible to an Enumerator if no block given.


Calls block once for each prime number, passing the prime as a parameter.


Upper bound of prime numbers. The iterator stops after it yields all prime numbers p <= ubound.


Prime.new returns an object extended by Prime::OldCompatibility in order to be compatible with Ruby 1.8, and Prime#each is overwritten by Prime::OldCompatibility#each.

Prime.new is now obsolete. Use Prime.instance.each or simply Prime.each.

Show source
Register or log in to add new notes.