るりまサーチ

最速Rubyリファレンスマニュアル検索!
22件ヒット [1-22件を表示] (0.057秒)
トップページ > モジュール:Enumerable[x] > クエリ:enumerator[x] > クエリ:each[x] > クエリ:each_with_index[x]

別のキーワード

  1. _builtin each
  2. _builtin each_line
  3. prime each
  4. each
  5. tsort tsort_each

ライブラリ

検索結果

Enumerable#each_with_index(*args) -> Enumerator (24366.0)

要素とそのインデックスをブロックに渡して繰り返します。

...繰り返すような
Enumerator
を返します。

Enumerator
#with_index は offset 引数を受け取りますが、
each_with_index
は受け取りません (引数はイテレータメソッドにそのまま渡されます)。

@param args イテレータメソッド (each など) にそのま...
...0, 15].each_with_index do |n, idx|
p [n, idx]
end
# => [5, 0]
# [10, 1]
# [15, 2]
//}

//emlist[引数ありの例][ruby]{
require 'stringio'
StringIO.new("foo|bar|baz").each_with_index("|") do |s, i|
p [s, i]
end
# => ["foo|", 0]
# ["bar|", 1]
# ["baz", 2]
//}

@see Enumerator#with_...

Enumerable#each_with_index(*args) {|item, index| ... } -> self (24266.0)

要素とそのインデックスをブロックに渡して繰り返します。

...繰り返すような
Enumerator
を返します。

Enumerator
#with_index は offset 引数を受け取りますが、
each_with_index
は受け取りません (引数はイテレータメソッドにそのまま渡されます)。

@param args イテレータメソッド (each など) にそのま...
...0, 15].each_with_index do |n, idx|
p [n, idx]
end
# => [5, 0]
# [10, 1]
# [15, 2]
//}

//emlist[引数ありの例][ruby]{
require 'stringio'
StringIO.new("foo|bar|baz").each_with_index("|") do |s, i|
p [s, i]
end
# => ["foo|", 0]
# ["bar|", 1]
# ["baz", 2]
//}

@see Enumerator#with_...