Class: RBI::Printer
- Extended by:
- T::Sig
- Defined in:
- lib/rbi/printer.rb
Instance Attribute Summary collapse
-
#current_indent ⇒ Object
readonly
Returns the value of attribute current_indent.
-
#in_visibility_group ⇒ Object
Returns the value of attribute in_visibility_group.
-
#max_line_length ⇒ Object
readonly
Returns the value of attribute max_line_length.
-
#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, max_line_length: nil) ⇒ Printer
constructor
A new instance of Printer.
- #print(string) ⇒ Object
- #printl(string) ⇒ Object
- #printn(string = nil) ⇒ Object
- #printt(string = nil) ⇒ Object
- #visit_all(nodes) ⇒ Object
- #visit_file(file) ⇒ Object
Methods inherited from Visitor
Constructor Details
#initialize(out: $stdout, indent: 0, print_locs: false, max_line_length: nil) ⇒ Printer
Returns a new instance of Printer.
30 31 32 33 34 35 36 37 38 |
# File 'lib/rbi/printer.rb', line 30 def initialize(out: $stdout, indent: 0, print_locs: false, max_line_length: nil) 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)) @max_line_length = max_line_length end |
Instance Attribute Details
#current_indent ⇒ Object (readonly)
Returns the value of attribute current_indent.
17 18 19 |
# File 'lib/rbi/printer.rb', line 17 def current_indent @current_indent end |
#in_visibility_group ⇒ Object
Returns the value of attribute in_visibility_group.
11 12 13 |
# File 'lib/rbi/printer.rb', line 11 def in_visibility_group @in_visibility_group end |
#max_line_length ⇒ Object (readonly)
Returns the value of attribute max_line_length.
20 21 22 |
# File 'lib/rbi/printer.rb', line 20 def max_line_length @max_line_length end |
#previous_node ⇒ Object (readonly)
Returns the value of attribute previous_node.
14 15 16 |
# File 'lib/rbi/printer.rb', line 14 def previous_node @previous_node end |
#print_locs ⇒ Object
Returns the value of attribute print_locs.
11 12 13 |
# File 'lib/rbi/printer.rb', line 11 def print_locs @print_locs end |
Instance Method Details
#dedent ⇒ Object
48 49 50 |
# File 'lib/rbi/printer.rb', line 48 def dedent @current_indent -= 2 end |
#indent ⇒ Object
43 44 45 |
# File 'lib/rbi/printer.rb', line 43 def indent @current_indent += 2 end |
#print(string) ⇒ Object
54 55 56 |
# File 'lib/rbi/printer.rb', line 54 def print(string) @out.print(string) end |
#printl(string) ⇒ Object
74 75 76 77 |
# File 'lib/rbi/printer.rb', line 74 def printl(string) printt printn(string) end |
#printn(string = nil) ⇒ Object
60 61 62 63 |
# File 'lib/rbi/printer.rb', line 60 def printn(string = nil) print(string) if string print("\n") end |
#printt(string = nil) ⇒ Object
67 68 69 70 |
# File 'lib/rbi/printer.rb', line 67 def printt(string = nil) print(" " * @current_indent) print(string) if string end |
#visit_all(nodes) ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/rbi/printer.rb', line 80 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
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/rbi/printer.rb', line 91 def visit_file(file) strictness = file.strictness if strictness printl("# typed: #{strictness}") end unless file.comments.empty? printn if strictness visit_all(file.comments) end unless file.root.empty? && file.root.comments.empty? printn if strictness || !file.comments.empty? visit(file.root) end end |