You don't need to count array offsets by hand!
Working with arrays in Ruby. Don't do this:
index = 0
for item in array
index += 1
puts "Item #{index}: #{item.inspect}"
end
Do this instead:
array.each_with_index do |item, index|
puts "Item #{index}: #{item.inspect}"
end
There are a bunch of handy methods like this. Read the Enumerable documentation and make your code that little bit more readable.
Leave feedback...
Commenting is closed for this article.

don’t use each_wth_index, use each_with_index instead. much better ;)
@Egze very good point – typo fixed. Thanks!