Class: RBI::Printer
- Extended by:
- T::Sig
- Defined in:
- lib/rbi/printer.rb
Instance Attribute Summary collapse
-
#in_visibility_group ⇒ Object
Returns the value of attribute in_visibility_group.
-
#previous_node ⇒ Object
readonly
Returns the value of attribute previous_node.
-
#print_locs ⇒ Object
Returns the value of attribute print_locs.
Instance Method Summary collapse
- #dedent ⇒ Object
- #indent ⇒ Object
-
#initialize(out: $stdout, indent: 0, print_locs: false) ⇒ Printer
constructor
A new instance of Printer.
- #print(string) ⇒ Object
- #printl(string) ⇒ Object
- #printn(string = nil) ⇒ Object
- #printt(string = nil) ⇒ Object
- #visit(node) ⇒ Object
- #visit_all(nodes) ⇒ Object
- #visit_file(file) ⇒ Object
Constructor Details
#initialize(out: $stdout, indent: 0, print_locs: false) ⇒ Printer
Returns a new instance of Printer.
15 16 17 18 19 20 21 22 |
# File 'lib/rbi/printer.rb', line 15 def initialize(out: $stdout, indent: 0, print_locs: false) super() @out = out @current_indent = indent @print_locs = print_locs @in_visibility_group = T.let(false, T::Boolean) @previous_node = T.let(nil, T.nilable(Node)) end |
Instance Attribute Details
#in_visibility_group ⇒ Object
Returns the value of attribute in_visibility_group.
9 10 11 |
# File 'lib/rbi/printer.rb', line 9 def in_visibility_group @in_visibility_group end |
#previous_node ⇒ Object (readonly)
Returns the value of attribute previous_node.
12 13 14 |
# File 'lib/rbi/printer.rb', line 12 def previous_node @previous_node end |
#print_locs ⇒ Object
Returns the value of attribute print_locs.
9 10 11 |
# File 'lib/rbi/printer.rb', line 9 def print_locs @print_locs end |
Instance Method Details
#dedent ⇒ Object
32 33 34 |
# File 'lib/rbi/printer.rb', line 32 def dedent @current_indent -= 2 end |
#indent ⇒ Object
27 28 29 |
# File 'lib/rbi/printer.rb', line 27 def indent @current_indent += 2 end |
#print(string) ⇒ Object
38 39 40 |
# File 'lib/rbi/printer.rb', line 38 def print(string) @out.print(string) end |
#printl(string) ⇒ Object
58 59 60 61 |
# File 'lib/rbi/printer.rb', line 58 def printl(string) printt printn(string) end |
#printn(string = nil) ⇒ Object
44 45 46 47 |
# File 'lib/rbi/printer.rb', line 44 def printn(string = nil) print(string) if string print("\n") end |
#printt(string = nil) ⇒ Object
51 52 53 54 |
# File 'lib/rbi/printer.rb', line 51 def printt(string = nil) print(" " * @current_indent) print(string) if string end |
#visit(node) ⇒ Object
69 70 71 72 |
# File 'lib/rbi/printer.rb', line 69 def visit(node) return unless node node.accept_printer(self) end |
#visit_all(nodes) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/rbi/printer.rb', line 75 def visit_all(nodes) previous_node = @previous_node @previous_node = nil nodes.each do |node| visit(node) @previous_node = node end @previous_node = previous_node end |
#visit_file(file) ⇒ Object
64 65 66 |
# File 'lib/rbi/printer.rb', line 64 def visit_file(file) file.accept_printer(self) end |