summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-10 20:38:13 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-10 20:38:13 +0000
commit0eebb8f1c0833b4897cfe2e5eb578951e86f88dd (patch)
tree98245502f12bf26f55e7800d49cc5bf6384d2526 /lib
parent05f087c844f0e1e7cfe323edcf591de64069a289 (diff)
* lib/prime.rb: Remove useless loop and block capture.
See [#10354] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48767 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/prime.rb30
1 files changed, 14 insertions, 16 deletions
diff --git a/lib/prime.rb b/lib/prime.rb
index ebe012b..b2b55f1 100644
--- a/lib/prime.rb
+++ b/lib/prime.rb
@@ -272,18 +272,18 @@ class Prime
end
# Iterates the given block for each prime number.
- def each(&block)
- return self.dup unless block
+ 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 = block.call(prime)
+ last_value = yield prime
end
else
loop do
- block.call(succ)
+ yield succ
end
end
end
@@ -350,19 +350,17 @@ class Prime
end
def succ
- loop do
- if (@step)
- @prime += @step
- @step = 6 - @step
- else
- case @prime
- when 1; @prime = 2
- when 2; @prime = 3
- when 3; @prime = 5; @step = 2
- end
+ if (@step)
+ @prime += @step
+ @step = 6 - @step
+ else
+ case @prime
+ when 1; @prime = 2
+ when 2; @prime = 3
+ when 3; @prime = 5; @step = 2
end
- return @prime
end
+ return @prime
end
alias next succ
def rewind
@@ -479,7 +477,7 @@ class Prime
#
# Iterates the given block over all prime numbers. Note that enumeration
# starts from the current position of internal pointer, not rewound.
- def each(&block)
+ def each
return @generator.dup unless block_given?
loop do
yield succ