Ruby 1.9.2 Reference Manual > All Libraries > Builtin Library > module Enumerable > each_with_index
each_with_index -> Enumeratoreach_with_index {|item, index| ... } -> self要素とそのインデックスをブロックに渡して繰り返します。
self を返します。
ブロックを省略した場合は、 要素とそのインデックスを繰り返すような Enumerator を返します。
例:
[5, 10, 15].each_with_index do |n, idx|
p [n, idx]
end
# => [5, 0]
# [10, 1]
# [15, 2]