Class: RBI::Type::Shape

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

Overview

A shape type like ‘String, age: Integer`.

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, #to_s, tuple, type_parameter, untyped, void

Constructor Details

#initialize(types) ⇒ Shape

: (Hash[(String | Symbol), Type] types) -> void



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

def initialize(types)
  super()
  @types = types
end

Instance Attribute Details

#typesObject (readonly)

: Hash[(String | Symbol), Type]



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

def types
  @types
end

Instance Method Details

#==(other) ⇒ Object

: (BasicObject other) -> bool



637
638
639
# File 'lib/rbi/type.rb', line 637

def ==(other)
  Shape === other && @types.sort_by { |t| t.first.to_s } == other.types.sort_by { |t| t.first.to_s }
end

#normalizeObject

: -> Type



653
654
655
# File 'lib/rbi/type.rb', line 653

def normalize
  self
end

#simplifyObject

: -> Type



659
660
661
# File 'lib/rbi/type.rb', line 659

def simplify
  self
end

#to_rbiObject

: -> String



643
644
645
646
647
648
649
# File 'lib/rbi/type.rb', line 643

def to_rbi
  if @types.empty?
    "{}"
  else
    "{ " + @types.map { |name, type| "#{name}: #{type.to_rbi}" }.join(", ") + " }"
  end
end