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, t_module, #to_s, tuple, type_alias, type_parameter, untyped, void
Constructor Details
#initialize ⇒ Proc
: -> void
754 755 756 757 758 759 |
# File 'lib/rbi/type.rb', line 754 def initialize super @proc_params = {} #: Hash[Symbol, Type] @proc_returns = Type.void #: Type @proc_bind = nil #: Type? end |
Instance Attribute Details
#proc_bind ⇒ Object (readonly)
: Type?
751 752 753 |
# File 'lib/rbi/type.rb', line 751 def proc_bind @proc_bind end |
#proc_params ⇒ Object (readonly)
: Hash[Symbol, Type]
745 746 747 |
# File 'lib/rbi/type.rb', line 745 def proc_params @proc_params end |
#proc_returns ⇒ Object (readonly)
: Type
748 749 750 |
# File 'lib/rbi/type.rb', line 748 def proc_returns @proc_returns end |
Instance Method Details
#==(other) ⇒ Object
: (BasicObject other) -> bool
763 764 765 766 767 768 769 770 |
# File 'lib/rbi/type.rb', line 763 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
791 792 793 794 |
# File 'lib/rbi/type.rb', line 791 def bind(type) @proc_bind = type self end |
#normalize ⇒ Object
: -> Type
823 824 825 |
# File 'lib/rbi/type.rb', line 823 def normalize self end |
#params(**params) ⇒ Object
: (**Type params) -> self
773 774 775 776 |
# File 'lib/rbi/type.rb', line 773 def params(**params) @proc_params = params self end |
#returns(type) ⇒ Object
: (untyped type) -> self
779 780 781 782 |
# File 'lib/rbi/type.rb', line 779 def returns(type) @proc_returns = type self end |
#simplify ⇒ Object
: -> Type
829 830 831 |
# File 'lib/rbi/type.rb', line 829 def simplify self end |
#to_rbi ⇒ Object
: -> String
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 |
# File 'lib/rbi/type.rb', line 798 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 |
#void ⇒ Object
: -> self
785 786 787 788 |
# File 'lib/rbi/type.rb', line 785 def void @proc_returns = RBI::Type.void self end |