You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: pattern_router.rb
    path of file: ./repos/i18n-tasks/lib/i18n/tasks/data/router
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

require 'i18n/tasks/key_pattern_matching'
require 'i18n/tasks/data/tr
    
      def route(locale, forest, &block)
        return to_enum(:route, locale, forest) unless block

        locale = locale.to_s
        out = {}
        forest.keys do |key, _node|
          pattern, path = routes.detect { |route| route[0] =~ key }
          if pattern
            key_match = $~
            path      = format(path, locale: locale)
            path.gsub!(/\\\d+/) { |m| key_match[m[1..].to_i] }
            (out[path] ||= Set.new) << "#{locale}.#{key}"
          else
            fail CommandError, "Cannot route key #{key}. Routes are #{@routes_config.inspect}"
          end
        end