End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Prime#each
each(ubound = nil, generator = EratosthenesGenerator.new, &block)
lib/prime.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.0.5/lib/prime.rb, line 212
def each(ubound = nil, generator = EratosthenesGenerator.new, &block)
generator.upper_bound = ubound
generator.each(&block)
end
Iterates the given block over all prime numbers.
Parameters
ubound-
Optional. An arbitrary positive number. The upper bound of enumeration. The method enumerates prime numbers infinitely if
uboundis nil. generator-
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.
Description
Calls block once for each prime number, passing the prime as a parameter.
ubound-
Upper bound of prime numbers. The iterator stops after it yields all prime numbers p <=
ubound.