class RBI::Attr

Attributes

Attributes

names[RW]
sigs[R]
visibility[RW]

Public Class Methods

new(name, names, visibility: Public.new, sigs: [], loc: nil, comments: []) click to toggle source
Calls superclass method RBI::NodeWithComments::new
# File lib/rbi/model.rb, line 353
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

Public Instance Methods

accept_printer(v) click to toggle source
# File lib/rbi/printer.rb, line 303
def accept_printer(v)
  previous_node = v.previous_node
  v.printn if previous_node && (!previous_node.oneline? || !oneline?)

  v.visit_all(comments)
  sigs.each { |sig| v.visit(sig) }
  v.printl("# #{loc}") if loc && v.print_locs
  v.printt
  unless v.in_visibility_group || visibility.public?
    v.print(visibility.visibility.to_s)
    v.print(" ")
  end
  case self
  when AttrAccessor
    v.print("attr_accessor")
  when AttrReader
    v.print("attr_reader")
  when AttrWriter
    v.print("attr_writer")
  end
  unless names.empty?
    v.print(" ")
    v.print(names.map { |name| ":#{name}" }.join(", "))
  end
  v.printn
end
compatible_with?(other) click to toggle source
# File lib/rbi/rewriters/merge_trees.rb, line 384
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
fully_qualified_names() click to toggle source
# File lib/rbi/model.rb, line 361
def fully_qualified_names; end
index_ids() click to toggle source
# File lib/rbi/index.rb, line 102
def index_ids
  fully_qualified_names
end
merge_with(other) click to toggle source
Calls superclass method RBI::NodeWithComments#merge_with
# File lib/rbi/rewriters/merge_trees.rb, line 391
def merge_with(other)
  return unless other.is_a?(Attr)
  super
  other.sigs.each do |sig|
    sigs << sig unless sigs.include?(sig)
  end
end
oneline?() click to toggle source
# File lib/rbi/printer.rb, line 331
def oneline?
  comments.empty? && sigs.empty?
end