enum_for(:each_with_index)$B$NAj0c(B

e$B$k$S$-$A$G$9!#e(B

Ruby 1.8.7e$B$He(BRuby 1.9e$B$Ne(B each_with_index
e$B$Ne(BEnumeratore$B$N5sF0$,0[$J$j$^$9!#e(B

require ‘enumerator’
RUBY_VERSION # => “1.8.6”
%w[foo bar].enum_for(:each_with_index).select {|x,i| i>=1 } # =>
[[“bar”, 1]]

require ‘enumerator’
RUBY_VERSION # => “1.8.7”
%w[foo bar].enum_for(:each_with_index).select {|x,i| i>=1 } # =>
[[“bar”, 1]]

require ‘enumerator’
RUBY_VERSION # => “1.9.0”
%w[foo bar].enum_for(:each_with_index).select {|x,i| i>=1 } # => [“bar”]

RUBY_VERSION # => “1.8.7”
%w[foo bar].each_with_index.select {|x,i| i>=1 } # => [[“bar”, 1]]

RUBY_VERSION # => “1.9.0”
%w[foo bar].each_with_index.select {|x,i| i>=1 } # => [“bar”]

At Mon, 12 May 2008 00:52:52 +0900,
[email protected] wrote:

Ruby 1.8.7とRuby 1.9の each_with_index のEnumeratorの挙動が異なります。
RUBY_VERSION # => “1.8.7”
%w[foo bar].each_with_index.select {|x,i| i>=1 } # => [[“bar”, 1]]

RUBY_VERSION # => “1.9.0”
%w[foo bar].each_with_index.select {|x,i| i>=1 } # => [“bar”]

 [ruby-dev:32708]→[ruby-dev:32745]という流れがあるようなので
1.9を修正しました。to_aを挟むと挙動が変わるというのは気持ち悪い
こともありますしね。