Repository: rails/rails
File: actionpack/lib/action_dispatch/routing/route_set.rb (Ruby)

Code before:
                  args.pop
                when ActionController::Parameters
                  args.pop.to_h
                end
              helper.call(self, name, args, options, url_strategy)
            end
          end
      end

      # strategy for building URLs to send to the client
      PATH    = ->(options) { ActionDispatch::Http::URL.path_for(options) }
      UNKNOWN = ->(options) { ActionDispatch::Http::URL.url_for(options) }

      attr_accessor :formatter, :set, :named_routes, :default_scope, :router
      attr_accessor :disable_clear_and_finalize, :resources_path_names
      attr_accessor :default_url_options, :draw_paths
      attr_reader :env_key, :polymorphic_mappings

      alias :routes :set

      def self.default_resources_path_names
        { new: "new", edit: "edit" }
      end

      def self.new_with_config(config)
        route_set_config = DEFAULT_CONFIG

        # engines apparently don't have this set
        if config.respond_to? :relative_url_root
          route_set_config.relative_url_root = config.relative_url_root
        end

        if config.respond_to? :api_only
          route_set_config.api_only = config.api_only
        end

        new route_set_config
      end

      Config = Struct.new :relative_url_root, :api_only

      DEFAULT_CONFIG = Config.new(nil, false)

      def initialize(config = DEFAULT_CONFIG)
        self.named_routes = NamedRouteCollection.new
        self.resources_path_names = self.class.default_resources_path_names
        self.default_url_options = {}
        self.draw_paths = []

        @config                     = config
        @append                     = []

Review comment (bug):
This has to be a bug. We mutate a constant in the next few lines which changes the config of future route sets. Duping the constant prevents this.

Code after:
                  args.pop
                when ActionController::Parameters
                  args.pop.to_h
                end
              helper.call(self, name, args, options, url_strategy)
            end
          end
      end

      # strategy for building URLs to send to the client
      PATH    = ->(options) { ActionDispatch::Http::URL.path_for(options) }
      UNKNOWN = ->(options) { ActionDispatch::Http::URL.url_for(options) }

      attr_accessor :formatter, :set, :named_routes, :router
      attr_accessor :disable_clear_and_finalize, :resources_path_names
      attr_accessor :default_url_options, :draw_paths
      attr_reader :env_key, :polymorphic_mappings

      alias :routes :set

      def self.default_resources_path_names
        { new: "new", edit: "edit" }
      end

      def self.new_with_config(config)
        route_set_config = DEFAULT_CONFIG.dup

        # engines apparently don't have this set
        if config.respond_to? :relative_url_root
          route_set_config.relative_url_root = config.relative_url_root
        end

        if config.respond_to? :api_only
          route_set_config.api_only = config.api_only
        end

        if config.respond_to? :default_scope
          route_set_config.default_scope = config.default_scope
        end

        new route_set_config
      end

      Config = Struct.new :relative_url_root, :api_only, :default_scope

      DEFAULT_CONFIG = Config.new(nil, false, nil)

      def initialize(config = DEFAULT_CONFIG.dup)
        self.named_routes = NamedRouteCollection.new
        self.resources_path_names = self.class.default_resources_path_names
        self.default_url_options = {}