Iterate With An Offset Index
> ["one", "two", "three"].each_with_index do |item, index|
puts "#{item} - #{index}"
end
one - 0
two - 1
three - 2
=> ["one", "two", "three"]> ["one", "two", "three"].each.with_index(1) do |item, index|
puts "#{item} - #{index}"
end
one - 1
two - 2
three - 3
=> ["one", "two", "three"]Last updated