Class: RBI::Type::TypeAlias

Inherits:
RBI::Type show all
Defined in:
lib/rbi/type.rb

Overview

A type alias that references another type by name like ‘MyTypeAlias`.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from RBI::Type

all, any, anything, attached_class, boolean, class_of, #eql?, generic, #hash, #nilable, nilable, #nilable?, #non_nilable, noreturn, parse_node, parse_string, proc, #rbs_string, self_type, shape, simple, t_class, t_module, #to_s, tuple, type_alias, type_parameter, untyped, void

Constructor Details

#initialize(name, aliased_type) ⇒ TypeAlias

: (String name, Type aliased_type) -> void



631
632
633
634
635
# File 'lib/rbi/type.rb', line 631

def initialize(name, aliased_type)
  super()
  @name = name
  @aliased_type = aliased_type
end

Instance Attribute Details

#aliased_typeObject (readonly)

: Type



628
629
630
# File 'lib/rbi/type.rb', line 628

def aliased_type
  @aliased_type
end

#nameObject (readonly)

: String



625
626
627
# File 'lib/rbi/type.rb', line 625

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object

: (BasicObject other) -> bool



639
640
641
# File 'lib/rbi/type.rb', line 639

def ==(other)
  TypeAlias === other && @name == other.name && @aliased_type == other.aliased_type
end

#normalizeObject

: -> Type



651
652
653
# File 'lib/rbi/type.rb', line 651

def normalize
  TypeAlias.new(name, aliased_type.normalize)
end

#simplifyObject

: -> Type



657
658
659
# File 'lib/rbi/type.rb', line 657

def simplify
  TypeAlias.new(name, aliased_type.simplify)
end

#to_rbiObject

: -> String



645
646
647
# File 'lib/rbi/type.rb', line 645

def to_rbi
  "#{name} = ::T.type_alias { #{aliased_type.to_rbi} }"
end