Ruby 2.3.0 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > Enumerableモジュール > each_with_index
each_with_index -> Enumerator[permalink][rdoc]each_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]