Class: RBI::File

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/rbi/model.rb,
lib/rbi/printer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(strictness: nil, comments: [], &block) ⇒ File

Returns a new instance of File.



135
136
137
138
139
140
# File 'lib/rbi/model.rb', line 135

def initialize(strictness: nil, comments: [], &block)
  @root = T.let(Tree.new, Tree)
  @strictness = strictness
  @comments = comments
  block&.call(self)
end

Instance Attribute Details

#commentsObject

Returns the value of attribute comments.



126
127
128
# File 'lib/rbi/model.rb', line 126

def comments
  @comments
end

#rootObject (readonly)

Returns the value of attribute root.



120
121
122
# File 'lib/rbi/model.rb', line 120

def root
  @root
end

#strictnessObject (readonly)

Returns the value of attribute strictness.



123
124
125
# File 'lib/rbi/model.rb', line 123

def strictness
  @strictness
end

Instance Method Details

#<<(node) ⇒ Object



143
144
145
# File 'lib/rbi/model.rb', line 143

def <<(node)
  @root << node
end

#accept_printer(v) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/rbi/printer.rb', line 90

def accept_printer(v)
  strictness = self.strictness
  if strictness
    v.printl("# typed: #{strictness}")
  end
  unless comments.empty?
    v.printn if strictness
    v.visit_all(comments)
  end

  unless root.empty?
    v.printn if strictness || !comments.empty?
    v.visit(root)
  end
end


107
108
109
110
# File 'lib/rbi/printer.rb', line 107

def print(out: $stdout, indent: 0, print_locs: false)
  p = Printer.new(out: out, indent: indent, print_locs: print_locs)
  p.visit_file(self)
end

#string(indent: 0, print_locs: false) ⇒ Object



113
114
115
116
117
# File 'lib/rbi/printer.rb', line 113

def string(indent: 0, print_locs: false)
  out = StringIO.new
  print(out: out, indent: indent, print_locs: print_locs)
  out.string
end