Issue #7493 has been updated by knu (Akinori MUSHA).


1.8??§ã?¯ã??next??? lib/generator.rb ??§å??è£?????????¦ã????¾ã?????

?????­ã????¯ï????®è???????¤ï?????欲ã???????¡ã?½ã????????Enumerator???next??§å???????¨ã???????®ã?¯ã????¤ã?¾ã??å¿?è¦???ªã????­ã????¯ã??渡ã????¦ã????ªã?????????§ã??????????????使ã????¹ã??1.8??§ã?¯æ?³å???????¦ã????¾ã???????§ã????????
??¤ã?¾ã?????äº?????????ªç???????¨ã????¦ã?¯ã??????????¯ä??å®???§ã????¨ã??????????¨ã?«ã?ªã????¾ã?????

?????????空ã?®ã????­ã????¯ï??{}ï¼???®è??価å?¤ã??nil??«ã?ªã???????¨ã?????????????¨ã??1.9以é????®ã????????nil???è¿??????¦ã???????®ã????ªç?¶ã?¨è??????????§ã??????????­ã??
Enumerable#to_a ???????????¨ã?§ã??nil???è¿?????????­ã????¯ã?§ç¹°???è¿??????¦ã????¾ã?????

??´ã????¨ã????????????????§ã????????1.8.7??¯ã????®é????®ä¿®æ­£ã????¥ã???????¨ã?¯ã???????ªã????§ã??????????­ã??
æ°???«ã?ªã??????????§ã???????°ã????­ã?¼ã?«ã?«ã?§å????¦ã???????¢ã?³ã?­ã?¼ã?????????????¦ã?¿ã?¦ã?????????????
ä¸?å¿? ruby_1_8 ??«ã?¯å?¥ã????¦ã???????¾ã?????

Index: lib/generator.rb
===================================================================
--- lib/generator.rb	(revision 38134)
+++ lib/generator.rb	(working copy)
@@ -69,7 +69,7 @@ class Generator
   def initialize(enum = nil, &block)
     if enum
       @block = proc { |g|
-	enum.each { |x| g.yield x }
+	enum.each { |x| g.yield x; nil }
       }
     else
       @block = block

----------------------------------------
Bug #7493: ?????­ã????¯ã??渡ã??????????´å???????????1è¦?ç´???®ã?¿ã??è¿????Enumerator??«å¯¾??????next?????????ç¶?????????¨ã??2度ç?®ã??StopIterationä¾?å¤??????ºç????????
https://bugs.ruby-lang.org/issues/7493#change-34315

Author: kachick (Kenichi Kamiya)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: Ruby 1.8.7
ruby -v: ruby 1.8.7 (2012-10-12 patchlevel 371) [x86_64-linux]


????????­ã????¯ä???????§å?????????????´å?????????????«è????¤ã????£ã??1è¦?ç´???®ã?¿ã??è¿??????¡ã?½ã??????????????Enumerator???ä½??????¨ã??
2度ç?®ã??next???StopIterationä¾?å¤????è¿????????????§ã?????
????????³ã?£ã??????????§ç¢ºèª?????????¡ã?½ã???????¯ã??以ä????®ç?©ã?§ã?????

* Array#index
* Array#find_index
* Array#rindex
* Enumerable#detect
* Enumerable#find

????????¯ã??1.8.7???1.9?????®ä??æ§???«æ?¼ã?????å·®ç?°ã?¨è??????????¹ã????¯ã????®ã?§ã???????????ï¼?
???????????????Enumerator??«å¯¾??????to_a???????????¨å?¨è??ç´??????«ã??Array???è¿????äº??????????
1.8.7??«æ?¼ã????¦ã????¨è??ç´?èµ°æ?»å?ºæ?¥ã????¹ã????ªç?¶ã?§ã?¯ç?¡ã???????¨æ???????¾ã????????

# to_a??¨ã?®å·®??°ã?¯ã??dbussink??®æ???????§æ????¥ã??????¨ã????ºæ?¥ã?¾ã????????
# https://github.com/rubinius/rubinius/pull/2063#issuecomment-10881875

  array = [:a, :b, :c]
  index_enum = array.index
  index_enum.to_a #=> [:a, :b, :c]
  index_enum.next #=> :a
  index_enum.next #=> StopIteration: iteration reached at end


-- 
http://bugs.ruby-lang.org/