method
with_index
v2_4_6 -
Show latest stable
- Class:
Enumerator
with_index(p1 = v1)public
Iterates the given block for each element with an index, which starts from offset. If no block is given, returns a new Enumerator that includes the index, starting from offset
offset |
the starting index to use |
1Note
Minor correction to Rubybull's examples?
Was your first example intended to be: a=[11,22,31,224,44] => [11, 22, 31, 224, 44] a.each.with_index { |val,index| puts "index: #{index} for #{val}" }