Class: RBI::Type::Proc
Overview
A proc type like ‘T.proc.void`.
Instance Attribute Summary collapse
-
#proc_bind ⇒ Object
readonly
: Type?.
-
#proc_params ⇒ Object
readonly
: Hash[Symbol, Type].
-
#proc_returns ⇒ Object
readonly
: Type.
Instance Method Summary collapse
-
#==(other) ⇒ Object
: (BasicObject other) -> bool.
-
#bind(type) ⇒ Object
: (untyped type) -> self.
-
#initialize ⇒ Proc
constructor
: -> void.
-
#normalize ⇒ Object
: -> Type.
-
#params(**params) ⇒ Object
: (**Type params) -> self.
-
#returns(type) ⇒ Object
: (untyped type) -> self.
-
#simplify ⇒ Object
: -> Type.
-
#to_rbi ⇒ Object
: -> String.
-
#void ⇒ Object
: -> self.
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
Instance Attribute Details
#proc_bind ⇒ Object (readonly)
: Type?
675 676 677 |
# File 'lib/rbi/type.rb', line 675 def proc_bind @proc_bind end |
#proc_params ⇒ Object (readonly)
: Hash[Symbol, Type]
669 670 671 |
# File 'lib/rbi/type.rb', line 669 def proc_params @proc_params end |
#proc_returns ⇒ Object (readonly)
: Type
672 673 674 |
# File 'lib/rbi/type.rb', line 672 def proc_returns @proc_returns end |
Instance Method Details
#==(other) ⇒ Object
: (BasicObject other) -> bool
687 688 689 690 691 692 693 694 |
# File 'lib/rbi/type.rb', line 687 def ==(other) return false unless Proc === other return false unless @proc_params == other.proc_params return false unless @proc_returns == other.proc_returns return false unless @proc_bind == other.proc_bind true end |
#bind(type) ⇒ Object
: (untyped type) -> self
715 716 717 718 |
# File 'lib/rbi/type.rb', line 715 def bind(type) @proc_bind = type self end |
#normalize ⇒ Object
: -> Type
747 748 749 |
# File 'lib/rbi/type.rb', line 747 def normalize self end |
#params(**params) ⇒ Object
: (**Type params) -> self
697 698 699 700 |
# File 'lib/rbi/type.rb', line 697 def params(**params) @proc_params = params self end |
#returns(type) ⇒ Object
: (untyped type) -> self
703 704 705 706 |
# File 'lib/rbi/type.rb', line 703 def returns(type) @proc_returns = type self end |
#simplify ⇒ Object
: -> Type
753 754 755 |
# File 'lib/rbi/type.rb', line 753 def simplify self end |
#to_rbi ⇒ Object
: -> String
722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 |
# File 'lib/rbi/type.rb', line 722 def to_rbi rbi = +"T.proc" if @proc_bind rbi << ".bind(#{@proc_bind})" end unless @proc_params.empty? rbi << ".params(" rbi << @proc_params.map { |name, type| "#{name}: #{type.to_rbi}" }.join(", ") rbi << ")" end rbi << case @proc_returns when Void ".void" else ".returns(#{@proc_returns})" end rbi end |