Class: RBI::Attr

Inherits:
NodeWithComments show all
Extended by:
T::Helpers, T::Sig
Includes:
Indexable
Defined in:
lib/rbi/model.rb,
lib/rbi/index.rb,
lib/rbi/rewriters/merge_trees.rb,
lib/rbi/rewriters/attr_to_methods.rb

Overview

Attributes

Direct Known Subclasses

AttrAccessor, AttrReader, AttrWriter

Instance Attribute Summary collapse

Attributes inherited from NodeWithComments

#comments

Attributes inherited from Node

#loc, #parent_tree

Instance Method Summary collapse

Methods inherited from NodeWithComments

#annotations, #version_requirements

Methods inherited from Node

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

Constructor Details

#initialize(name, names, visibility: Public.new, sigs: [], loc: nil, comments: []) ⇒ Attr

: (Symbol name, Array names, ?visibility: Visibility, ?sigs: Array, ?loc: Loc?, ?comments: Array) -> void



314
315
316
317
318
319
# File 'lib/rbi/model.rb', line 314

def initialize(name, names, visibility: Public.new, sigs: [], loc: nil, comments: [])
  super(loc: loc, comments: comments)
  @names = T.let([name, *names], T::Array[Symbol])
  @visibility = visibility
  @sigs = sigs
end

Instance Attribute Details

#namesObject (readonly)

: Array



305
306
307
# File 'lib/rbi/model.rb', line 305

def names
  @names
end

#sigsObject (readonly)

: Array



311
312
313
# File 'lib/rbi/model.rb', line 311

def sigs
  @sigs
end

#visibilityObject

: Visibility



308
309
310
# File 'lib/rbi/model.rb', line 308

def visibility
  @visibility
end

Instance Method Details

#compatible_with?(other) ⇒ Boolean

: (Node other) -> bool

Returns:

  • (Boolean)


394
395
396
397
398
399
# File 'lib/rbi/rewriters/merge_trees.rb', line 394

def compatible_with?(other)
  return false unless other.is_a?(Attr)
  return false unless names == other.names

  sigs.empty? || other.sigs.empty? || sigs == other.sigs
end

#convert_to_methodsObject



58
# File 'lib/rbi/rewriters/attr_to_methods.rb', line 58

def convert_to_methods; end

#fully_qualified_namesObject



322
# File 'lib/rbi/model.rb', line 322

def fully_qualified_names; end

#index_idsObject

: -> Array



109
110
111
# File 'lib/rbi/index.rb', line 109

def index_ids
  fully_qualified_names
end

#merge_with(other) ⇒ Object

: (Node other) -> void



403
404
405
406
407
408
409
410
# File 'lib/rbi/rewriters/merge_trees.rb', line 403

def merge_with(other)
  return unless other.is_a?(Attr)

  super
  other.sigs.each do |sig|
    sigs << sig unless sigs.include?(sig)
  end
end