Ruby 1.8.7 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > Enumerableモジュール > each_with_index
each_with_index -> Enumerable::Enumeratorenum_with_index -> Enumerable::Enumeratoreach_with_index {|item, index| ... } -> self要素とそのインデックスをブロックに渡して繰り返します。
self を返します。
例:
[5, 10, 15].each_with_index do |n, idx|
p [n, idx]
end
# => [5, 0]
# [10, 1]
# [15, 2]