hash.keys.each_with_index do |key, index| value = hash[key] print "key: #{key}, value: #{value}, index: #{index}\n" # use key, value and index as desired end
hash.each_with_index do |(key, value), index|
print "key: #{key}, value: #{value}, index: #{index}\n"
# use key, value and index as desired
end