When moving over an iteration such as:
array.each do |row|
puts "Current row count: " + row.current_row_index
# do some more stuff
end
Is there a way to get the index of the current iteration / row? Obviously I can just throw in a counter, but I'm curious if there's a shortcut for an index function that shows it's current position.
Been digging through the available methods via pry, however I've not seen anything that seems to do this out of the box.
array.each_with_index |row, index|
puts index
end
If you need exactly the index
array.each_index do |index|
puts index
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With