Use customized starting index with each_with_index while using Enumerator 🙌🏼

In your Ruby on Rails project, you can use each.with_index(starting-index) instead of each_with_index if you wanted to customize starting index of enumerator(Array)

Code snippet 📌

# Normal loop over enumerator
('a'..'e').each_with_index do |k,i|
  puts "#{k} - #{i}"
end

# Output
a - 0
b - 1
c - 2
d - 3
e - 4


# Loop with customized index over enumerator
('a'..'e').each.with_index(100) do |k,i|
  puts "#{k} - #{i}"
end

# Output
a - 100
b - 101
c - 102
d - 103
e - 104