Class: RBI::Method
- Inherits:
-
NodeWithComments
show all
- Extended by:
- T::Sig
- Includes:
- Indexable
- Defined in:
- lib/rbi/model.rb,
lib/rbi/index.rb,
lib/rbi/printer.rb,
lib/rbi/rewriters/merge_trees.rb
Overview
Instance Attribute Summary collapse
#comments
Attributes inherited from Node
#loc, #parent_tree
Instance Method Summary
collapse
#annotations
Methods inherited from Node
#detach, #group_kind, #parent_conflict_tree, #parent_scope, #print, #print_blank_line_before, #replace, #string
Constructor Details
#initialize(name, params: [], is_singleton: false, visibility: Public.new, sigs: [], loc: nil, comments: [], &block) ⇒ Method
Returns a new instance of Method.
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
|
# File 'lib/rbi/model.rb', line 505
def initialize(
name,
params: [],
is_singleton: false,
visibility: Public.new,
sigs: [],
loc: nil,
comments: [],
&block
)
super(loc: loc, comments: )
@name = name
@params = params
@is_singleton = is_singleton
@visibility = visibility
@sigs = sigs
block&.call(self)
end
|
Instance Attribute Details
#is_singleton ⇒ Object
Returns the value of attribute is_singleton.
485
486
487
|
# File 'lib/rbi/model.rb', line 485
def is_singleton
@is_singleton
end
|
#name ⇒ Object
Returns the value of attribute name.
479
480
481
|
# File 'lib/rbi/model.rb', line 479
def name
@name
end
|
#params ⇒ Object
Returns the value of attribute params.
482
483
484
|
# File 'lib/rbi/model.rb', line 482
def params
@params
end
|
#sigs ⇒ Object
Returns the value of attribute sigs.
491
492
493
|
# File 'lib/rbi/model.rb', line 491
def sigs
@sigs
end
|
#visibility ⇒ Object
Returns the value of attribute visibility.
488
489
490
|
# File 'lib/rbi/model.rb', line 488
def visibility
@visibility
end
|
Instance Method Details
#<<(param) ⇒ Object
525
526
527
|
# File 'lib/rbi/model.rb', line 525
def <<(param)
@params << param
end
|
#accept_printer(v) ⇒ Object
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
|
# File 'lib/rbi/printer.rb', line 382
def accept_printer(v)
print_blank_line_before(v)
v.visit_all()
v.visit_all(sigs)
v.printl("# #{loc}") if loc && v.print_locs
v.printt
unless v.in_visibility_group || visibility.public?
v.print(visibility.visibility.to_s)
v.print(" ")
end
v.print("def ")
v.print("self.") if is_singleton
v.print(name)
unless params.empty?
v.print("(")
if inline_params?
params.each_with_index do |param, index|
v.print(", ") if index > 0
v.visit(param)
end
else
v.printn
v.indent
params.each_with_index do |param, pindex|
v.printt
v.visit(param)
v.print(",") if pindex < params.size - 1
param..each_with_index do |, cindex|
if cindex > 0
param.(v, last: pindex == params.size - 1)
else
v.print(" ")
end
v.print("# #{}")
end
v.printn
end
v.dedent
end
v.print(")")
end
v.print("; end")
v.printn
end
|
#compatible_with?(other) ⇒ Boolean
453
454
455
456
457
458
|
# File 'lib/rbi/rewriters/merge_trees.rb', line 453
def compatible_with?(other)
return false unless other.is_a?(Method)
return false unless name == other.name
return false unless params == other.params
sigs.empty? || other.sigs.empty? || sigs == other.sigs
end
|
#fully_qualified_name ⇒ Object
530
531
532
533
534
535
536
|
# File 'lib/rbi/model.rb', line 530
def fully_qualified_name
if is_singleton
"#{parent_scope&.fully_qualified_name}::#{name}"
else
"#{parent_scope&.fully_qualified_name}##{name}"
end
end
|
#index_ids ⇒ Object
119
120
121
|
# File 'lib/rbi/index.rb', line 119
def index_ids
[fully_qualified_name]
end
|
#inline_params? ⇒ Boolean
435
436
437
|
# File 'lib/rbi/printer.rb', line 435
def inline_params?
params.all? { |p| p..empty? }
end
|
#merge_with(other) ⇒ Object
461
462
463
464
465
466
467
|
# File 'lib/rbi/rewriters/merge_trees.rb', line 461
def merge_with(other)
return unless other.is_a?(Method)
super
other.sigs.each do |sig|
sigs << sig unless sigs.include?(sig)
end
end
|
#oneline? ⇒ Boolean
430
431
432
|
# File 'lib/rbi/printer.rb', line 430
def oneline?
.empty? && sigs.empty? && inline_params?
end
|
#to_s ⇒ Object
539
540
541
|
# File 'lib/rbi/model.rb', line 539
def to_s
"#{fully_qualified_name}(#{params.join(", ")})"
end
|