class SyntaxTree::MatchVisitor

This visitor transforms the AST into a Ruby pattern matching expression that would match correctly against the AST.

Attributes

q[R]

Public Class Methods

new(q) click to toggle source
# File lib/syntax_tree/match_visitor.rb, line 9
def initialize(q)
  @q = q
end

Public Instance Methods

visit(node) click to toggle source
Calls superclass method SyntaxTree::BasicVisitor#visit
# File lib/syntax_tree/match_visitor.rb, line 13
def visit(node)
  case node
  when Node
    super
  when String
    # pp will split up a string on newlines and concat them together using a
    # "+" operator. This breaks the pattern matching expression. So instead
    # we're going to check here for strings and manually put the entire
    # value into the output buffer.
    q.text(node.inspect)
  else
    node.pretty_print(q)
  end
end