File: visitor.rb

package info (click to toggle)
ruby-rabl-rails 0.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 288 kB
  • sloc: ruby: 1,630; makefile: 4
file content (21 lines) | stat: -rw-r--r-- 362 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module Visitors
  class Visitor
    def visit(node)
      dispatch(node)
    end

    def visit_Array a
      a.each { |n| dispatch(n) }
    end

    private

    DISPATCH = Hash.new do |hash, node_class|
      hash[node_class] = "visit_#{node_class.name.split('::').last}"
    end

    def dispatch(node)
      send DISPATCH[node.class], node
    end
  end
end