1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
marcandre 2014-12-10 20:38:13 +00:00
parent 05f087c844
commit 0eebb8f1c0
2 changed files with 19 additions and 16 deletions

View file

@ -1,3 +1,8 @@
Thu Dec 11 05:37:52 2014 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
* lib/prime.rb: Remove useless loop and block capture.
See [#10354]
Thu Dec 11 04:27:24 2014 Koichi Sasada <ko1@atdot.net> Thu Dec 11 04:27:24 2014 Koichi Sasada <ko1@atdot.net>
* vm_core.h: introduce new field * vm_core.h: introduce new field

View file

@ -272,18 +272,18 @@ class Prime
end end
# Iterates the given block for each prime number. # Iterates the given block for each prime number.
def each(&block) def each
return self.dup unless block return self.dup unless block_given?
if @ubound if @ubound
last_value = nil last_value = nil
loop do loop do
prime = succ prime = succ
break last_value if prime > @ubound break last_value if prime > @ubound
last_value = block.call(prime) last_value = yield prime
end end
else else
loop do loop do
block.call(succ) yield succ
end end
end end
end end
@ -350,19 +350,17 @@ class Prime
end end
def succ def succ
loop do if (@step)
if (@step) @prime += @step
@prime += @step @step = 6 - @step
@step = 6 - @step else
else case @prime
case @prime when 1; @prime = 2
when 1; @prime = 2 when 2; @prime = 3
when 2; @prime = 3 when 3; @prime = 5; @step = 2
when 3; @prime = 5; @step = 2
end
end end
return @prime
end end
return @prime
end end
alias next succ alias next succ
def rewind def rewind
@ -479,7 +477,7 @@ class Prime
# #
# Iterates the given block over all prime numbers. Note that enumeration # Iterates the given block over all prime numbers. Note that enumeration
# starts from the current position of internal pointer, not rewound. # starts from the current position of internal pointer, not rewound.
def each(&block) def each
return @generator.dup unless block_given? return @generator.dup unless block_given?
loop do loop do
yield succ yield succ