class Parlour::RbiGenerator::TypeAlias

Represents a type alias.

Attributes

type[R]

Public Class Methods

new(generator, name:, type:, &block) click to toggle source

Creates a new type alias.

@param name [String] The name of the alias. @param value [String] The type to alias to.

Calls superclass method Parlour::RbiGenerator::RbiObject::new
# File lib/parlour/rbi_generator/type_alias.rb, line 18
def initialize(generator, name:, type:, &block)
  super(generator, name)
  @type = type
  yield_self(&block) if block
end

Public Instance Methods

==(other) click to toggle source

Returns true if this instance is equal to another type alias.

@param other [Object] The other instance. If this is not a {TypeAlias} (or a

subclass of it), this will always return false.

@return [Boolean]

# File lib/parlour/rbi_generator/type_alias.rb, line 34
def ==(other)
  TypeAlias === other && name == other.name && type == other.type
end
describe() click to toggle source

Returns a human-readable brief string description of this code.

@return [String]

# File lib/parlour/rbi_generator/type_alias.rb, line 91
def describe
  "Type Alias (#{name} = #{type})"
end
generalize_from_rbi!() click to toggle source
# File lib/parlour/rbi_generator/type_alias.rb, line 96
def generalize_from_rbi!
  @type = TypeParser.parse_single_type(@type) if String === @type
end
generate_rbi(indent_level, options) click to toggle source

Generates the RBI lines for this type alias.

@param indent_level [Integer] The indentation level to generate the lines at. @param options [Options] The formatting options to use. @return [Array<String>] The RBI lines, formatted as specified.

# File lib/parlour/rbi_generator/type_alias.rb, line 49
def generate_rbi(indent_level, options)
  [options.indented(indent_level,
    "#{name} = T.type_alias { #{String === @type ? @type : @type.generate_rbi} }"
  )]
end
merge_into_self(others) click to toggle source

Given an array of {TypeAlias} 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<RbiGenerator::RbiObject>] An array of other

{TypeAlias} instances.

@return [void]

# File lib/parlour/rbi_generator/type_alias.rb, line 83
def merge_into_self(others)
  # We don't need to change anything! We only merge identical type alias
end
mergeable?(others) click to toggle source

Given an array of {TypeAlias} instances, returns true if they may be merged into this instance using {merge_into_self}. This is always false.

@param others [Array<RbiGenerator::RbiObject>] An array of other

{TypeAlias} instances.

@return [Boolean] Whether this instance may be merged with them.

# File lib/parlour/rbi_generator/type_alias.rb, line 66
def mergeable?(others)
  others.all? { |other| self == other }
end