Mega Code Archive

 
Categories / Ruby / Array
 

Each with index and block

['a', 'b', 'c'].each_with_index do |item, index|   puts "At position #{index}: #{item}" end # At position 0: a # At position 1: b # At position 2: c