Class: RBI::Type::Shape
Overview
A shape type like ‘String, age: Integer`.
Instance Attribute Summary collapse
-
#types ⇒ Object
readonly
: Hash[(String | Symbol), Type].
Instance Method Summary collapse
-
#==(other) ⇒ Object
: (BasicObject other) -> bool.
-
#initialize(types) ⇒ Shape
constructor
: (Hash[(String | Symbol), Type] types) -> void.
-
#normalize ⇒ Object
: -> Type.
-
#simplify ⇒ Object
: -> Type.
-
#to_rbi ⇒ Object
: -> String.
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(types) ⇒ Shape
: (Hash[(String | Symbol), Type] types) -> void
706 707 708 709 |
# File 'lib/rbi/type.rb', line 706 def initialize(types) super() @types = types end |
Instance Attribute Details
#types ⇒ Object (readonly)
: Hash[(String | Symbol), Type]
703 704 705 |
# File 'lib/rbi/type.rb', line 703 def types @types end |
Instance Method Details
#==(other) ⇒ Object
: (BasicObject other) -> bool
713 714 715 |
# File 'lib/rbi/type.rb', line 713 def ==(other) Shape === other && @types.sort_by { |t| t.first.to_s } == other.types.sort_by { |t| t.first.to_s } end |
#normalize ⇒ Object
: -> Type
729 730 731 |
# File 'lib/rbi/type.rb', line 729 def normalize self end |
#simplify ⇒ Object
: -> Type
735 736 737 |
# File 'lib/rbi/type.rb', line 735 def simplify self end |
#to_rbi ⇒ Object
: -> String
719 720 721 722 723 724 725 |
# File 'lib/rbi/type.rb', line 719 def to_rbi if @types.empty? "{}" else "{ " + @types.map { |name, type| "#{name}: #{type.to_rbi}" }.join(", ") + " }" end end |