Class: RBI::Type::Shape
- Extended by:
- T::Sig
- Defined in:
- lib/rbi/type.rb
Overview
A shape type like ‘String, age: Integer`.
Instance Attribute Summary collapse
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(types) ⇒ Shape
constructor
A new instance of Shape.
- #to_rbi ⇒ Object
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
Returns a new instance of Shape.
364 365 366 367 |
# File 'lib/rbi/type.rb', line 364 def initialize(types) super() @types = types end |
Instance Attribute Details
#types ⇒ Object (readonly)
Returns the value of attribute types.
361 362 363 |
# File 'lib/rbi/type.rb', line 361 def types @types end |
Instance Method Details
#==(other) ⇒ Object
370 371 372 |
# File 'lib/rbi/type.rb', line 370 def ==(other) Shape === other && @types.sort_by { |t| t.first.to_s } == other.types.sort_by { |t| t.first.to_s } end |
#to_rbi ⇒ Object
375 376 377 378 379 380 381 |
# File 'lib/rbi/type.rb', line 375 def to_rbi if @types.empty? "{}" else "{ " + @types.map { |name, type| "#{name}: #{type.to_rbi}" }.join(", ") + " }" end end |