Class: RBI::Type::Shape
- Inherits:
-
Type
- Object
- Type
- RBI::Type::Shape
- Defined in:
- lib/rbi/type.rb
Overview
A shape type like {name: String, age: Integer}.
Instance Attribute Summary collapse
- #types ⇒ Object readonly
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(types) ⇒ Shape
constructor
A new instance of Shape.
- #normalize ⇒ Object
- #simplify ⇒ Object
- #to_rbi ⇒ Object
Constructor Details
#initialize(types) ⇒ Shape
Returns a new instance of Shape.
706 707 708 709 |
# File 'lib/rbi/type.rb', line 706 def initialize(types) super() @types = types end |
Instance Attribute Details
#types ⇒ Object (readonly)
703 704 705 |
# File 'lib/rbi/type.rb', line 703 def types @types end |
Instance Method Details
#==(other) ⇒ Object
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
736 737 738 |
# File 'lib/rbi/type.rb', line 736 def normalize self end |
#simplify ⇒ Object
742 743 744 |
# File 'lib/rbi/type.rb', line 742 def simplify self end |
#to_rbi ⇒ Object
719 720 721 722 723 724 725 726 727 728 729 730 731 732 |
# File 'lib/rbi/type.rb', line 719 def to_rbi if @types.empty? "{}" else "{ " + @types.map do |name, type| case name when Symbol "#{name}: #{type.to_rbi}" when String "#{name.inspect} => #{type.to_rbi}" end end.join(", ") + " }" end end |