Class: RBI::Method
- Inherits:
-
NodeWithComments
- Object
- Node
- NodeWithComments
- RBI::Method
- Includes:
- Indexable
- Defined in:
- lib/rbi/model.rb,
lib/rbi/index.rb,
lib/rbi/rewriters/merge_trees.rb
Overview
Methods and args
Instance Attribute Summary collapse
Attributes inherited from NodeWithComments
Attributes inherited from Node
Instance Method Summary collapse
- #<<(param) ⇒ Object
- #add_block_param(name) ⇒ Object
- #add_kw_opt_param(name, default_value) ⇒ Object
- #add_kw_param(name) ⇒ Object
- #add_kw_rest_param(name) ⇒ Object
- #add_no_kw_param ⇒ Object
- #add_opt_param(name, default_value) ⇒ Object
- #add_param(name) ⇒ Object
- #add_rest_param(name) ⇒ Object
- #add_sig(params: [], return_type: "void", bind_type: nil, is_abstract: false, is_override: false, is_overridable: false, is_final: false, type_params: [], checked: nil, &block) ⇒ Object
- #compatible_with?(other) ⇒ Boolean
- #fully_qualified_name ⇒ Object
- #index_ids ⇒ Object
-
#initialize(name, params: nil, is_singleton: false, visibility: Public::DEFAULT, sigs: nil, loc: nil, comments: nil, &block) ⇒ Method
constructor
A new instance of Method.
- #merge_with(other) ⇒ Object
- #params ⇒ Object
- #sigs? ⇒ Boolean
- #to_s ⇒ Object
Methods inherited from NodeWithComments
#annotations, #comments?, #version_requirements
Methods inherited from Node
#detach, #parent_conflict_tree, #parent_scope, #print, #rbs_print, #rbs_string, #replace, #satisfies_version?, #string
Constructor Details
#initialize(name, params: nil, is_singleton: false, visibility: Public::DEFAULT, sigs: nil, loc: nil, comments: nil, &block) ⇒ Method
Returns a new instance of Method.
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 |
# File 'lib/rbi/model.rb', line 491 def initialize( name, params: nil, is_singleton: false, visibility: Public::DEFAULT, sigs: nil, loc: nil, comments: nil, &block ) super(loc: loc, comments: comments) @name = name.to_s #: String @params = params #: Array[Param]? @is_singleton = is_singleton @visibility = visibility @sigs = sigs #: Array[Sig]? block&.call(self) end |
Instance Attribute Details
#is_singleton ⇒ Object
464 465 466 |
# File 'lib/rbi/model.rb', line 464 def is_singleton @is_singleton end |
#name ⇒ Object (readonly)
456 457 458 |
# File 'lib/rbi/model.rb', line 456 def name @name end |
#sigs ⇒ Object
470 471 472 |
# File 'lib/rbi/model.rb', line 470 def sigs @sigs ||= [] end |
#visibility ⇒ Object
467 468 469 |
# File 'lib/rbi/model.rb', line 467 def visibility @visibility end |
Instance Method Details
#<<(param) ⇒ Object
511 512 513 |
# File 'lib/rbi/model.rb', line 511 def <<(param) params << param end |
#add_block_param(name) ⇒ Object
551 552 553 |
# File 'lib/rbi/model.rb', line 551 def add_block_param(name) params << BlockParam.new(name) end |
#add_kw_opt_param(name, default_value) ⇒ Object
536 537 538 |
# File 'lib/rbi/model.rb', line 536 def add_kw_opt_param(name, default_value) params << KwOptParam.new(name, default_value) end |
#add_kw_param(name) ⇒ Object
531 532 533 |
# File 'lib/rbi/model.rb', line 531 def add_kw_param(name) params << KwParam.new(name) end |
#add_kw_rest_param(name) ⇒ Object
541 542 543 |
# File 'lib/rbi/model.rb', line 541 def add_kw_rest_param(name) params << KwRestParam.new(name) end |
#add_no_kw_param ⇒ Object
546 547 548 |
# File 'lib/rbi/model.rb', line 546 def add_no_kw_param params << NoKwParam.new end |
#add_opt_param(name, default_value) ⇒ Object
521 522 523 |
# File 'lib/rbi/model.rb', line 521 def add_opt_param(name, default_value) params << OptParam.new(name, default_value) end |
#add_param(name) ⇒ Object
516 517 518 |
# File 'lib/rbi/model.rb', line 516 def add_param(name) params << ReqParam.new(name) end |
#add_rest_param(name) ⇒ Object
526 527 528 |
# File 'lib/rbi/model.rb', line 526 def add_rest_param(name) params << RestParam.new(name) end |
#add_sig(params: [], return_type: "void", bind_type: nil, is_abstract: false, is_override: false, is_overridable: false, is_final: false, type_params: [], checked: nil, &block) ⇒ Object
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 |
# File 'lib/rbi/model.rb', line 565 def add_sig( params: [], return_type: "void", bind_type: nil, is_abstract: false, is_override: false, is_overridable: false, is_final: false, type_params: [], checked: nil, &block ) sig = Sig.new( params: params, return_type: return_type, bind_type: bind_type, is_abstract: is_abstract, is_override: is_override, is_overridable: is_overridable, is_final: is_final, type_params: type_params, checked: checked, &block ) sigs << sig end |
#compatible_with?(other) ⇒ Boolean
466 467 468 469 470 471 472 473 474 475 476 477 478 |
# File 'lib/rbi/rewriters/merge_trees.rb', line 466 def compatible_with?(other) return false unless other.is_a?(Method) return false unless name == other.name return false unless params.size == other.params.size if sigs.empty? && other.sigs.empty? compatible_params?(other) elsif sigs.empty? || other.sigs.empty? true else compatible_params?(other) && sigs == other.sigs end end |
#fully_qualified_name ⇒ Object
593 594 595 596 597 598 599 |
# File 'lib/rbi/model.rb', line 593 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
114 115 116 |
# File 'lib/rbi/index.rb', line 114 def index_ids [fully_qualified_name] end |
#merge_with(other) ⇒ Object
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
# File 'lib/rbi/rewriters/merge_trees.rb', line 482 def merge_with(other) return unless other.is_a?(Method) super if sigs.empty? && !other.sigs.empty? @params = other.params.dup @sigs = other.sigs.dup return end @params = merge_params(params, other.params) rename_sigs_params(sigs, @params) other.sigs.each do |sig| sigs << sig unless sigs.include?(sig) end end |
#params ⇒ Object
459 460 461 |
# File 'lib/rbi/model.rb', line 459 def params @params ||= [] end |
#sigs? ⇒ Boolean
475 476 477 |
# File 'lib/rbi/model.rb', line 475 def sigs? !@sigs.nil? && !@sigs.empty? end |
#to_s ⇒ Object
603 604 605 |
# File 'lib/rbi/model.rb', line 603 def to_s "#{fully_qualified_name}(#{params.join(", ")})" end |