A better way to use each_with_index

Instead of using some_array.each_with_index consider using some_array.each.with_index instead.

with_index takes an argument which allows you to set the base number to calculate the index. By default it is 0 and thus 0 indexed. But you can supply a 1 if you prefer or any other number for that matter.

array = %w{a b c}
array.each.with_index {|element, index| puts "Index #{index}: #{element}" }

# Index 0: a
# Index 1: b
# Index 2: c


array.each.with_index(1000) {|element, index| puts "Index #{index}: #{element}" }

# Index 1000: a
# Index 1001: b
# Index 1002: c