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