Class: RBI::AttrAccessor
- Inherits:
-
Attr
- Object
- Node
- NodeWithComments
- Attr
- RBI::AttrAccessor
- 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
Attributes inherited from NodeWithComments
Attributes inherited from Node
Instance Method Summary collapse
-
#compatible_with?(other) ⇒ Boolean
: (Node other) -> bool.
-
#convert_to_methods ⇒ Object
: -> Array.
-
#fully_qualified_names ⇒ Object
: -> Array.
- #initialize(name, *names, visibility: Public.new, sigs: [], loc: nil, comments: [], &block) ⇒ AttrAccessor constructor
-
#to_s ⇒ Object
: -> String.
Methods inherited from Attr
Methods included from Indexable
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, *names, visibility: Public.new, sigs: [], loc: nil, comments: [], &block) ⇒ AttrAccessor
327 328 329 330 |
# File 'lib/rbi/model.rb', line 327 def initialize(name, *names, visibility: Public.new, sigs: [], loc: nil, comments: [], &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
432 433 434 |
# File 'lib/rbi/rewriters/merge_trees.rb', line 432 def compatible_with?(other) other.is_a?(AttrAccessor) && super end |
#convert_to_methods ⇒ Object
: -> Array
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/rbi/rewriters/attr_to_methods.rb', line 122 def convert_to_methods sig, attribute_type = parse_sig names.flat_map do |name| [ create_getter_method(name.to_s, sig, visibility, loc, comments), create_setter_method(name.to_s, sig, attribute_type, visibility, loc, comments), ] end end |
#fully_qualified_names ⇒ Object
: -> Array
334 335 336 337 |
# File 'lib/rbi/model.rb', line 334 def fully_qualified_names parent_name = parent_scope&.fully_qualified_name names.flat_map { |name| ["#{parent_name}##{name}", "#{parent_name}##{name}="] } end |
#to_s ⇒ Object
: -> String
341 342 343 344 |
# File 'lib/rbi/model.rb', line 341 def to_s symbols = names.map { |name| ":#{name}" }.join(", ") "#{parent_scope&.fully_qualified_name}.attr_accessor(#{symbols})" end |