Class: RBI::Class

Inherits:
Scope show all
Extended by:
T::Sig
Defined in:
lib/rbi/model.rb,
lib/rbi/printer.rb,
lib/rbi/rewriters/merge_trees.rb

Direct Known Subclasses

TEnum, TStruct

Instance Attribute Summary collapse

Attributes inherited from Tree

#nodes

Attributes inherited from NodeWithComments

#comments

Attributes inherited from Node

#loc, #parent_tree

Instance Method Summary collapse

Methods inherited from Scope

#accept_printer, #dup_empty, #index_ids, #print_body, #to_s

Methods included from Indexable

#index_ids

Methods inherited from Tree

#<<, #accept_printer, #empty?, #group_nodes!, #index, #merge, #nest_non_public_methods!, #nest_singleton_methods!, #oneline?, #sort_nodes!

Methods inherited from NodeWithComments

#merge_with, #oneline?

Methods inherited from Node

#accept_printer, #detach, #group_kind, #merge_with, #oneline?, #parent_conflict_tree, #parent_scope, #print, #replace, #string

Constructor Details

#initialize(name, superclass_name: nil, loc: nil, comments: [], &block) ⇒ Class

Returns a new instance of Class.



209
210
211
212
213
214
# File 'lib/rbi/model.rb', line 209

def initialize(name, superclass_name: nil, loc: nil, comments: [], &block)
  super(loc: loc, comments: comments) {}
  @name = name
  @superclass_name = superclass_name
  block&.call(self)
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



195
196
197
# File 'lib/rbi/model.rb', line 195

def name
  @name
end

#superclass_nameObject

Returns the value of attribute superclass_name.



198
199
200
# File 'lib/rbi/model.rb', line 198

def superclass_name
  @superclass_name
end

Instance Method Details

#compatible_with?(other) ⇒ Boolean

Returns:

  • (Boolean)


315
316
317
# File 'lib/rbi/rewriters/merge_trees.rb', line 315

def compatible_with?(other)
  other.is_a?(Class) && superclass_name == other.superclass_name
end

#fully_qualified_nameObject



217
218
219
220
# File 'lib/rbi/model.rb', line 217

def fully_qualified_name
  return name if name.start_with?("::")
  "#{parent_scope&.fully_qualified_name}::#{name}"
end


229
230
231
232
233
234
235
236
237
238
# File 'lib/rbi/printer.rb', line 229

def print_header(v)
  v.printt("class #{name}")
  superclass = superclass_name
  v.print(" < #{superclass}") if superclass
  if empty?
    v.printn("; end")
  else
    v.printn
  end
end