summaryrefslogtreecommitdiff
path: root/ext/psych/lib/psych/visitors/visitor.rb
blob: 3f4ba64e57d6ae8b81f89e243baf0af15f5e98b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# frozen_string_literal: true
module Psych
  module Visitors
    class Visitor
      def accept target
        visit target
      end

      private

      DISPATCH = Hash.new do |hash, klass|
        hash[klass] = "visit_#{klass.name.gsub('::', '_')}"
      end

      def visit target
        send DISPATCH[target.class], target
      end
    end
  end
end