Class: RBI::AttrReader

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

Instance Attribute Summary

Attributes inherited from Attr

#names, #sigs, #visibility

Attributes inherited from NodeWithComments

#comments

Attributes inherited from Node

#loc, #parent_tree

Instance Method Summary collapse

Methods inherited from Attr

#index_ids, #merge_with, #sigs?

Methods included from Indexable

#index_ids

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, *names, visibility: Public::DEFAULT, sigs: nil, loc: nil, comments: nil, &block) ⇒ AttrReader

: ( | Symbol name, | *Symbol names, | ?visibility: Visibility, | ?sigs: Array?, | ?loc: Loc?, | ?comments: Array? | ) ?{ (AttrReader node) -> void } -> void



403
404
405
406
# File 'lib/rbi/model.rb', line 403

def initialize(name, *names, visibility: Public::DEFAULT, sigs: nil, loc: nil, comments: nil, &block)
  super(name, names, loc: loc, visibility: visibility, sigs: sigs, comments: comments)
  block&.call(self)
end

Instance Method Details

#compatible_with?(other) ⇒ Boolean

: (Node other) -> bool

Returns:

  • (Boolean)


442
443
444
# File 'lib/rbi/rewriters/merge_trees.rb', line 442

def compatible_with?(other)
  other.is_a?(AttrReader) && super
end

#convert_to_methodsObject

: -> Array



145
146
147
148
149
# File 'lib/rbi/rewriters/attr_to_methods.rb', line 145

def convert_to_methods
  sig, _ = parse_sig

  names.map { |name| create_getter_method(name.to_s, sig, visibility, loc, comments) }
end

#fully_qualified_namesObject

: -> Array



410
411
412
413
# File 'lib/rbi/model.rb', line 410

def fully_qualified_names
  parent_name = parent_scope&.fully_qualified_name
  names.map { |name| "#{parent_name}##{name}" }
end

#to_sObject

: -> String



417
418
419
420
# File 'lib/rbi/model.rb', line 417

def to_s
  symbols = names.map { |name| ":#{name}" }.join(", ")
  "#{parent_scope&.fully_qualified_name}.attr_reader(#{symbols})"
end