Class: Prime8::Generators::PrimeGenerator
- Inherits:
-
Object
- Object
- Prime8::Generators::PrimeGenerator
show all
- Includes:
- Enumerable
- Defined in:
- lib/prime_8/generators/prime_generator.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of PrimeGenerator.
4
5
6
|
# File 'lib/prime_8/generators/prime_generator.rb', line 4
def initialize(ubound = nil)
@ubound = ubound
end
|
Instance Method Details
#each ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/prime_8/generators/prime_generator.rb', line 28
def each
return self.dup unless block_given?
if @ubound
last_value = nil
loop do
prime = succ
break last_value if prime > @ubound
last_value = yield prime
end
else
loop do
yield succ
end
end
end
|
#next ⇒ Object
20
21
22
|
# File 'lib/prime_8/generators/prime_generator.rb', line 20
def next
raise NotImplementedError, "need to define `next'"
end
|
#rewind ⇒ Object
24
25
26
|
# File 'lib/prime_8/generators/prime_generator.rb', line 24
def rewind
raise NotImplementedError, "need to define `rewind'"
end
|
#succ ⇒ Object
16
17
18
|
# File 'lib/prime_8/generators/prime_generator.rb', line 16
def succ
raise NotImplementedError, "need to define `succ'"
end
|
#upper_bound ⇒ Object
12
13
14
|
# File 'lib/prime_8/generators/prime_generator.rb', line 12
def upper_bound
@ubound
end
|
#upper_bound=(ubound) ⇒ Object
8
9
10
|
# File 'lib/prime_8/generators/prime_generator.rb', line 8
def upper_bound=(ubound)
@ubound = ubound
end
|
#with_object(obj) ⇒ Object
46
47
48
49
50
51
|
# File 'lib/prime_8/generators/prime_generator.rb', line 46
def with_object(obj)
return enum_for(:with_object) unless block_given?
each do |prime|
yield prime, obj
end
end
|