Class: RBI::Class

Inherits:
Scope show all
Defined in:
lib/rbi/model.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

#dup_empty, #index_ids, #to_s

Methods included from Indexable

#index_ids

Methods inherited from Tree

#<<, #add_sig_templates!, #annotate!, #deannotate!, #empty?, #filter_versions!, #flatten_singleton_methods!, #flatten_visibilities!, #group_nodes!, #index, #merge, #nest_non_public_members!, #nest_singleton_methods!, #nest_top_level_members!, #replace_attributes_with_methods!, #sort_nodes!, #translate_rbs_sigs!

Methods inherited from NodeWithComments

#annotations, #comments?, #merge_with, #version_requirements

Methods inherited from Node

#detach, #merge_with, #parent_conflict_tree, #parent_scope, #print, #rbs_print, #rbs_string, #replace, #satisfies_version?, #string

Constructor Details

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

: ( | String name, | ?superclass_name: String?, | ?loc: Loc?, | ?comments: Array? | ) ?{ (Class node) -> void } -> void



230
231
232
233
234
235
# File 'lib/rbi/model.rb', line 230

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

Instance Attribute Details

#nameObject (readonly)

: String



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

def name
  @name
end

#superclass_nameObject

: String?



222
223
224
# File 'lib/rbi/model.rb', line 222

def superclass_name
  @superclass_name
end

Instance Method Details

#compatible_with?(other) ⇒ Boolean

: (Node other) -> bool

Returns:

  • (Boolean)


388
389
390
# File 'lib/rbi/rewriters/merge_trees.rb', line 388

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

#fully_qualified_nameObject

: -> String



239
240
241
242
243
# File 'lib/rbi/model.rb', line 239

def fully_qualified_name
  return name if name.start_with?("::")

  "#{parent_scope&.fully_qualified_name}::#{name}"
end