enum_for(:each_with_index)の相違

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.7Ruby 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.9to_a

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs