try  with  names.each_with_index do |elem, index| ....