Class: RBI::AttrWriter
- Inherits:
-
Attr
show all
- Extended by:
- T::Sig
- 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
#comments
Attributes inherited from Node
#loc, #parent_tree
Instance Method Summary
collapse
Methods inherited from Attr
#index_ids, #merge_with
Methods included from Indexable
#index_ids
#annotations, #merge_with, #version_requirements
Methods inherited from Node
#detach, #merge_with, #parent_conflict_tree, #parent_scope, #print, #replace, #satisfies_version?, #string
Constructor Details
#initialize(name, *names, visibility: Public.new, sigs: [], loc: nil, comments: [], &block) ⇒ AttrWriter
Returns a new instance of AttrWriter.
465
466
467
468
|
# File 'lib/rbi/model.rb', line 465
def initialize(name, *names, visibility: Public.new, sigs: [], loc: nil, comments: [], &block)
super(name, names, loc: loc, visibility: visibility, sigs: sigs, comments: )
block&.call(self)
end
|
Instance Method Details
#compatible_with?(other) ⇒ Boolean
445
446
447
|
# File 'lib/rbi/rewriters/merge_trees.rb', line 445
def compatible_with?(other)
other.is_a?(AttrWriter) && super
end
|
#convert_to_methods ⇒ Object
163
164
165
166
167
|
# File 'lib/rbi/rewriters/attr_to_methods.rb', line 163
def convert_to_methods
sig, attribute_type = parse_sig
names.map { |name| create_setter_method(name.to_s, sig, attribute_type, visibility, loc, ) }
end
|
#fully_qualified_names ⇒ Object
471
472
473
474
|
# File 'lib/rbi/model.rb', line 471
def fully_qualified_names
parent_name = parent_scope&.fully_qualified_name
names.map { |name| "#{parent_name}##{name}=" }
end
|
#to_s ⇒ Object
477
478
479
480
|
# File 'lib/rbi/model.rb', line 477
def to_s
symbols = names.map { |name| ":#{name}" }.join(", ")
"#{parent_scope&.fully_qualified_name}.attr_writer(#{symbols})"
end
|