Class: RBI::Struct

Inherits:
Scope show all
Defined in:
lib/rbi/model.rb,
lib/rbi/rewriters/merge_trees.rb

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, #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, members: [], keyword_init: false, loc: nil, comments: [], &block) ⇒ Struct

: (String name, ?members: Array, ?keyword_init: bool, ?loc: Loc?, ?comments: Array) ?{ (Struct struct) -> void } -> void



253
254
255
256
257
258
259
# File 'lib/rbi/model.rb', line 253

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

Instance Attribute Details

#keyword_initObject

: bool



250
251
252
# File 'lib/rbi/model.rb', line 250

def keyword_init
  @keyword_init
end

#membersObject

: Array



247
248
249
# File 'lib/rbi/model.rb', line 247

def members
  @members
end

#nameObject

: String



244
245
246
# File 'lib/rbi/model.rb', line 244

def name
  @name
end

Instance Method Details

#compatible_with?(other) ⇒ Boolean

: (Node other) -> bool

Returns:

  • (Boolean)


378
379
380
# File 'lib/rbi/rewriters/merge_trees.rb', line 378

def compatible_with?(other)
  other.is_a?(Struct) && members == other.members && keyword_init == other.keyword_init
end

#fully_qualified_nameObject

: -> String



263
264
265
266
267
# File 'lib/rbi/model.rb', line 263

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

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