ruby-changes:36686
From: marcandre <ko1@a...>
Date: Thu, 11 Dec 2014 05:38:23 +0900 (JST)
Subject: [ruby-changes:36686] marcandRe: r48767 (trunk): * lib/prime.rb: Remove useless loop and block capture.
marcandre 2014-12-11 05:38:13 +0900 (Thu, 11 Dec 2014) New Revision: 48767 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48767 Log: * lib/prime.rb: Remove useless loop and block capture. See [#10354] Modified files: trunk/ChangeLog trunk/lib/prime.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 48766) +++ ChangeLog (revision 48767) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Dec 11 05:37:52 2014 Marc-Andre Lafortune <ruby-core@m...> + + * lib/prime.rb: Remove useless loop and block capture. + See [#10354] + Thu Dec 11 04:27:24 2014 Koichi Sasada <ko1@a...> * vm_core.h: introduce new field Index: lib/prime.rb =================================================================== --- lib/prime.rb (revision 48766) +++ lib/prime.rb (revision 48767) @@ -272,18 +272,18 @@ class Prime https://github.com/ruby/ruby/blob/trunk/lib/prime.rb#L272 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 https://github.com/ruby/ruby/blob/trunk/lib/prime.rb#L350 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 https://github.com/ruby/ruby/blob/trunk/lib/prime.rb#L477 # # 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/