Class: RBI::Attr
- Inherits:
-
NodeWithComments
- Object
- Node
- NodeWithComments
- RBI::Attr
- Extended by:
- T::Helpers, T::Sig
- Includes:
- Indexable
- Defined in:
- lib/rbi/model.rb,
lib/rbi/index.rb,
lib/rbi/printer.rb,
lib/rbi/rewriters/merge_trees.rb
Overview
Attributes
Direct Known Subclasses
Instance Attribute Summary collapse
-
#names ⇒ Object
Returns the value of attribute names.
-
#sigs ⇒ Object
readonly
Returns the value of attribute sigs.
-
#visibility ⇒ Object
Returns the value of attribute visibility.
Attributes inherited from NodeWithComments
Attributes inherited from Node
Instance Method Summary collapse
- #accept_printer(v) ⇒ Object
- #compatible_with?(other) ⇒ Boolean
- #fully_qualified_names ⇒ Object
- #index_ids ⇒ Object
-
#initialize(name, *names, visibility: Visibility::Public, sigs: [], loc: nil, comments: []) ⇒ Attr
constructor
A new instance of Attr.
- #merge_with(other) ⇒ Object
- #oneline? ⇒ Boolean
Methods inherited from Node
#detach, #group_kind, #parent_conflict_tree, #parent_scope, #print, #replace, #string
Constructor Details
#initialize(name, *names, visibility: Visibility::Public, sigs: [], loc: nil, comments: []) ⇒ Attr
Returns a new instance of Attr.
298 299 300 301 302 303 |
# File 'lib/rbi/model.rb', line 298 def initialize(name, *names, visibility: Visibility::Public, 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
#names ⇒ Object
Returns the value of attribute names.
280 281 282 |
# File 'lib/rbi/model.rb', line 280 def names @names end |
#sigs ⇒ Object (readonly)
Returns the value of attribute sigs.
286 287 288 |
# File 'lib/rbi/model.rb', line 286 def sigs @sigs end |
#visibility ⇒ Object
Returns the value of attribute visibility.
283 284 285 |
# File 'lib/rbi/model.rb', line 283 def visibility @visibility end |
Instance Method Details
#accept_printer(v) ⇒ Object
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/rbi/printer.rb', line 273 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 == 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) ⇒ Boolean
342 343 344 345 346 |
# File 'lib/rbi/rewriters/merge_trees.rb', line 342 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 ⇒ Object
306 |
# File 'lib/rbi/model.rb', line 306 def fully_qualified_names; end |
#index_ids ⇒ Object
102 103 104 |
# File 'lib/rbi/index.rb', line 102 def index_ids fully_qualified_names end |
#merge_with(other) ⇒ Object
349 350 351 352 353 354 355 |
# File 'lib/rbi/rewriters/merge_trees.rb', line 349 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? ⇒ Boolean
301 302 303 |
# File 'lib/rbi/printer.rb', line 301 def oneline? comments.empty? && sigs.empty? end |