Class | Prime::PseudoPrimeGenerator |
In: |
lib/backports/1.9.1/stdlib/prime.rb
|
Parent: | Object |
each_with_index | -> | with_index |
see Enumeratorwith_index. |
# File lib/backports/1.9.1/stdlib/prime.rb, line 227 227: def initialize(ubound = nil) 228: @ubound = ubound 229: end
Iterates the given block for each prime numbers.
# File lib/backports/1.9.1/stdlib/prime.rb, line 259 259: def each(&block) 260: return self.dup unless block 261: if @ubound 262: last_value = nil 263: loop do 264: prime = succ 265: break last_value if prime > @ubound 266: last_value = block.call(prime) 267: end 268: else 269: loop do 270: block.call(succ) 271: end 272: end 273: end
Rewinds the internal position for enumeration.
See Enumeratorrewind.
# File lib/backports/1.9.1/stdlib/prime.rb, line 254 254: def rewind 255: raise NotImplementedError, "need to define `rewind'" 256: end
returns the next pseudo-prime number, and move the internal position forward.
PseudoPrimeGeneratorsucc raises NotImplementedError.
# File lib/backports/1.9.1/stdlib/prime.rb, line 242 242: def succ 243: raise NotImplementedError, "need to define `succ'" 244: end
# File lib/backports/1.9.1/stdlib/prime.rb, line 231 231: def upper_bound=(ubound) 232: @ubound = ubound 233: end