class Parlour::RbsGenerator::Constant
Represents a constant definition.
Attributes
Public Class Methods
Creates a new constant definition.
@param name [String] The name of the constant. @param value [String] The value of the constant, as a Ruby code string.
eigenclass of the current namespace.
# File lib/parlour/rbs_generator/constant.rb, line 19 def initialize(generator, name, type:, &block) super(generator, name) @type = type yield_self(&block) if block end
Public Instance Methods
Returns true if this instance is equal to another extend.
@param other [Object] The other instance. If this is not a {Extend} (or a
subclass of it), this will always return false.
@return [Boolean]
# File lib/parlour/rbs_generator/constant.rb, line 35 def ==(other) Constant === other && name == other.name && type == other.type end
Returns a human-readable brief string description of this code.
@return [String]
# File lib/parlour/rbs_generator/constant.rb, line 90 def describe "Constant (#{name} = #{type})" end
Generates the RBS lines for this constant.
@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/constant.rb, line 50 def generate_rbs(indent_level, options) [options.indented(indent_level, "#{name}: #{String === @type ? @type : @type.generate_rbs}")] end
Given an array of {Constant} instances, merges them into this one. This particular implementation will simply do nothing, as instances are only mergeable if they are indentical. You MUST ensure that {mergeable?} is true for those instances.
@param others [Array<RbsGenerator::RbsObject>] An array of other
{Extend} instances.
@return [void]
# File lib/parlour/rbs_generator/constant.rb, line 82 def merge_into_self(others) # We don't need to change anything! We only merge identical constants end
Given an array of {Constant} instances, returns true if they may be merged into this instance using {merge_into_self}. This is always false.
@param others [Array<RbsGenerator::RbsObject>] An array of other
{Constant} instances.
@return [Boolean] Whether this instance may be merged with them.
# File lib/parlour/rbs_generator/constant.rb, line 65 def mergeable?(others) others.all? { |other| self == other } end