method
with_index
v1_9_2_180 -
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 an enumerator.
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}" }