Repository: rails/rails
File: actionpack/lib/action_dispatch/journey/visitors.rb (Ruby)

Code before:
          when :SYMBOL
            seed << node.left
          when :SLASH
            seed << node.left
          when :CAT
            visit(node.right, visit(node.left, seed))
          when :STAR
            visit(node.left, seed)
          when :OR
            last_child = node.children.last
            node.children.each do |c|
              visit(c, seed)
              seed << "|" unless last_child == c
            end
            seed
          when :GROUP
            visit(node.left, seed << "(") << ")"
          else
            raise "Unknown node type: #{node.type}"
          end
        end

        INSTANCE = new

        private
          alias_method :visit, :accept
      end

      # class String < FunctionalVisitor # :nodoc:
      #   private
      #     def binary(node, seed)
      #       visit(node.right, visit(node.left, seed))
      #     end
      #
      #     def nary(node, seed)
      #       last_child = node.children.last
      #       node.children.inject(seed) { |s, c|
      #         string = visit(c, s)
      #         string << "|" unless last_child == c
      #         string
      #       }
      #     end
      #
      #     def terminal(node, seed)
      #       seed + node.left
      #     end
      #
      #     def visit_GROUP(node, seed)
      #       visit(node.left, seed.dup << "(") << ")"
      #     end
      #

Review comment (suggestion):
Definitely :+1: to not re-allocating with `+`, I saw that as well.

I was looking into double dispatch visiting where nodes define

```
def visit(v, seed)
  v.visit_group(seed)
end
```

but I think yours would be faster because there's less indirection? I'll try out a benchmark to verify.

Anyways, is it worth even having this alias? We could just always call `accept` inside the visitor

Code after:
          when :SYMBOL
            seed << node.left
          when :SLASH
            seed << node.left
          when :CAT
            accept(node.right, accept(node.left, seed))
          when :STAR
            accept(node.left, seed)
          when :OR
            last_child = node.children.last
            node.children.each do |c|
              accept(c, seed)
              seed << "|" unless last_child == c
            end
            seed
          when :GROUP
            accept(node.left, seed << "(") << ")"
          else
            raise "Unknown node type: #{node.type}"
          end
        end

        INSTANCE = new
      end

      # class String < FunctionalVisitor # :nodoc:
      #   private
      #     def binary(node, seed)
      #       visit(node.right, visit(node.left, seed))
      #     end
      #
      #     def nary(node, seed)
      #       last_child = node.children.last
      #       node.children.inject(seed) { |s, c|
      #         string = visit(c, s)
      #         string << "|" unless last_child == c
      #         string
      #       }
      #     end
      #
      #     def terminal(node, seed)
      #       seed + node.left
      #     end
      #
      #     def visit_GROUP(node, seed)
      #       visit(node.left, seed.dup << "(") << ")"
      #     end
      #
      #     INSTANCE = new
      # end