Class: RBI::Type::Proc
Overview
A proc type like ‘T.proc.void`.
Instance Attribute Summary collapse
Instance Method Summary
collapse
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 ⇒ Proc
400
401
402
403
404
405
|
# File 'lib/rbi/type.rb', line 400
def initialize
super
@proc_params = T.let({}, T::Hash[Symbol, Type])
@proc_returns = T.let(Type.void, Type)
@proc_bind = T.let(nil, T.nilable(Type))
end
|
Instance Attribute Details
#proc_bind ⇒ Object
Returns the value of attribute proc_bind.
397
398
399
|
# File 'lib/rbi/type.rb', line 397
def proc_bind
@proc_bind
end
|
#proc_params ⇒ Object
Returns the value of attribute proc_params.
391
392
393
|
# File 'lib/rbi/type.rb', line 391
def proc_params
@proc_params
end
|
#proc_returns ⇒ Object
Returns the value of attribute proc_returns.
394
395
396
|
# File 'lib/rbi/type.rb', line 394
def proc_returns
@proc_returns
end
|
Instance Method Details
#==(other) ⇒ Object
408
409
410
411
412
413
414
415
|
# File 'lib/rbi/type.rb', line 408
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
436
437
438
439
|
# File 'lib/rbi/type.rb', line 436
def bind(type)
@proc_bind = type
self
end
|
#params(**params) ⇒ Object
418
419
420
421
|
# File 'lib/rbi/type.rb', line 418
def params(**params)
@proc_params = params
self
end
|
#returns(type) ⇒ Object
424
425
426
427
|
# File 'lib/rbi/type.rb', line 424
def returns(type)
@proc_returns = type
self
end
|
#to_rbi ⇒ Object
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
|
# File 'lib/rbi/type.rb', line 442
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
430
431
432
433
|
# File 'lib/rbi/type.rb', line 430
def void
@proc_returns = RBI::Type.void
self
end
|