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.
-
#params(**params) ⇒ Object
: (**Type params) -> self.
-
#returns(type) ⇒ Object
: (untyped type) -> self.
-
#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?
393 394 395 |
# File 'lib/rbi/type.rb', line 393 def proc_bind @proc_bind end |
#proc_params ⇒ Object (readonly)
: Hash[Symbol, Type]
387 388 389 |
# File 'lib/rbi/type.rb', line 387 def proc_params @proc_params end |
#proc_returns ⇒ Object (readonly)
: Type
390 391 392 |
# File 'lib/rbi/type.rb', line 390 def proc_returns @proc_returns end |
Instance Method Details
#==(other) ⇒ Object
: (BasicObject other) -> bool
405 406 407 408 409 410 411 412 |
# File 'lib/rbi/type.rb', line 405 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
433 434 435 436 |
# File 'lib/rbi/type.rb', line 433 def bind(type) @proc_bind = type self end |
#params(**params) ⇒ Object
: (**Type params) -> self
415 416 417 418 |
# File 'lib/rbi/type.rb', line 415 def params(**params) @proc_params = params self end |
#returns(type) ⇒ Object
: (untyped type) -> self
421 422 423 424 |
# File 'lib/rbi/type.rb', line 421 def returns(type) @proc_returns = type self end |
#to_rbi ⇒ Object
: -> String
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 |
# File 'lib/rbi/type.rb', line 440 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 |