Class: DTC::Utils::Visitor::Printer

Inherits:
Forwarder
  • Object
show all
Defined in:
lib/dtc/utils/visitor.rb

Overview

Printing forwarding visitor

The constructor accepts a block to replace the default printing mecanism.

Instance Attribute Summary

Attributes inherited from Forwarder

#next_visitor

Instance Method Summary collapse

Constructor Details

#initialize(next_visitor = nil, &printer) ⇒ Printer

:yields: depth, method, *args



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/dtc/utils/visitor.rb', line 79

def initialize next_visitor = nil, &printer # :yields: depth, method, *args
  @printer = printer || lambda { |depth, method, *args|
    puts(
      ("  " * depth) +
      method.inspect +
      (args.empty? ? "" : " " + args.inspect)
    )
  }
  @depth = 0
  super next_visitor
end

Instance Method Details

#add(*args) ⇒ Object



99
100
101
102
# File 'lib/dtc/utils/visitor.rb', line 99

def add *args
  print :add, *args
  super
end

#enter(*args) ⇒ Object



90
91
92
93
94
# File 'lib/dtc/utils/visitor.rb', line 90

def enter *args
  print :enter, *args
  @depth += 1
  super
end

#leaveObject



95
96
97
98
# File 'lib/dtc/utils/visitor.rb', line 95

def leave
  @depth -= 1
  super
end