Sha256: 744af3f925b737915897dd9ae6c335a5b49a0de85fe86f5fa5febd6d550447d0

Contents?: true

Size: 774 Bytes

Versions: 2

Compression:

Stored size: 774 Bytes

Contents

# frozen_string_literal: true

#
# Copyright (c) 2018-present, Blue Marble Payroll, LLC
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#

module Logicality
  module Interpreter
    # This is a base class for traversing a node.
    class NodeVisitor
      def visit(node)
        return nil unless node

        visitor_name = method_name(node)

        if respond_to?(visitor_name)
          send(visitor_name, node)
        else
          generic_visit(node)
        end
      end

      private

      def generic_visit(node)
        raise ArgumentError, "No visitor method: #{method_name(node)}"
      end

      def method_name(node)
        "visit_#{node.name}"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
logicality-2.0.0 lib/logicality/interpreter/node_visitor.rb
logicality-1.0.5 lib/logicality/interpreter/node_visitor.rb