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.



156
157
158
159
160
161
# File 'lib/rbi/model.rb', line 156

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.



147
148
149
# File 'lib/rbi/model.rb', line 147

def comments
  @comments
end

#rootObject

Returns the value of attribute root.



141
142
143
# File 'lib/rbi/model.rb', line 141

def root
  @root
end

#strictnessObject

Returns the value of attribute strictness.



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

def strictness
  @strictness
end

Instance Method Details

#<<(node) ⇒ Object



164
165
166
# File 'lib/rbi/model.rb', line 164

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

#accept_printer(v) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/rbi/printer.rb', line 105

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? && root.comments.empty?
    v.printn if strictness || !comments.empty?
    v.visit(root)
  end
end

#empty?Boolean

Returns:

  • (Boolean)


169
170
171
# File 'lib/rbi/model.rb', line 169

def empty?
  @root.empty?
end


129
130
131
132
# File 'lib/rbi/printer.rb', line 129

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

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



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

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