class Parlour::RbsGenerator::Attribute
Represents an attribute reader, writer or accessor.
Attributes
The kind of attribute this is; one of :writer
, :reader
, or :accessor
. @return [Symbol]
The type of this attribute.
Public Class Methods
Creates a new attribute. @note You should use {Namespace#create_attribute} rather than this directly.
@param generator [RbsGenerator] The current RbsGenerator
. @param name [String] The name of this attribute. @param kind [Symbol] The kind of attribute this is; one of :writer, :reader or
:accessor.
@param type [String, Types::Type] This attribute's type. @param block A block which the new instance yields itself to. @return [void]
Parlour::RbsGenerator::Method::new
# File lib/parlour/rbs_generator/attribute.rb, line 27 def initialize(generator, name, kind, type, &block) @type = type @kind = kind case kind when :accessor, :reader super(generator, name, [MethodSignature.new([], type)], &block) when :writer super(generator, name, [MethodSignature.new([ Parameter.new(name, type: type) ], type)], &block) else raise 'unknown kind' end end
Public Instance Methods
Returns true if this instance is equal to another attribute.
@param other [Object] The other instance. If this is not a {Attribute}
(or a subclass of it), this will always return false.
@return [Boolean]
# File lib/parlour/rbs_generator/attribute.rb, line 75 def ==(other) T.must( super(other) && Attribute === other && kind == other.kind ) end
Generates the RBS lines for this arbstrary code.
@param indent_level [Integer] The indentation level to generate the lines at. @param options [Options] The formatting options to use. @return [Array<String>] The RBS lines, formatted as specified.
# File lib/parlour/rbs_generator/attribute.rb, line 62 def generate_rbs(indent_level, options) generate_comments(indent_level, options) + [options.indented( indent_level, "attr_#{kind} #{name}: #{String === @type ? @type : @type.generate_rbs}" )] end