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
-
#is_singleton ⇒ Object
: bool.
-
#name ⇒ Object
readonly
: String.
-
#sigs ⇒ Object
: -> Array.
-
#visibility ⇒ Object
: Visibility.
Attributes inherited from NodeWithComments
Attributes inherited from Node
Instance Method Summary collapse
-
#<<(param) ⇒ Object
: (Param param) -> void.
-
#add_block_param(name) ⇒ Object
: (String name) -> void.
-
#add_kw_opt_param(name, default_value) ⇒ Object
: (String name, String default_value) -> void.
-
#add_kw_param(name) ⇒ Object
: (String name) -> void.
-
#add_kw_rest_param(name) ⇒ Object
: (String name) -> void.
-
#add_opt_param(name, default_value) ⇒ Object
: (String name, String default_value) -> void.
-
#add_param(name) ⇒ Object
: (String name) -> void.
-
#add_rest_param(name) ⇒ Object
: (String name) -> void.
- #add_sig(params: [], return_type: "void", is_abstract: false, is_override: false, is_overridable: false, is_final: false, type_params: [], checked: nil, &block) ⇒ Object
-
#compatible_with?(other) ⇒ Boolean
: (Node other) -> bool.
-
#fully_qualified_name ⇒ Object
: -> String.
-
#index_ids ⇒ Object
: -> Array.
- #initialize(name, params: nil, is_singleton: false, visibility: Public::DEFAULT, sigs: nil, loc: nil, comments: nil, &block) ⇒ Method constructor
-
#merge_with(other) ⇒ Object
: (Node other) -> void.
-
#params ⇒ Object
: -> Array.
-
#sigs? ⇒ Boolean
: -> bool.
-
#to_s ⇒ Object
: -> String.
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
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
: bool
464 465 466 |
# File 'lib/rbi/model.rb', line 464 def is_singleton @is_singleton end |
#name ⇒ Object (readonly)
: String
456 457 458 |
# File 'lib/rbi/model.rb', line 456 def name @name end |
#visibility ⇒ Object
: Visibility
467 468 469 |
# File 'lib/rbi/model.rb', line 467 def visibility @visibility end |
Instance Method Details
#<<(param) ⇒ Object
: (Param param) -> void
511 512 513 |
# File 'lib/rbi/model.rb', line 511 def <<(param) params << param end |
#add_block_param(name) ⇒ Object
: (String name) -> void
546 547 548 |
# File 'lib/rbi/model.rb', line 546 def add_block_param(name) params << BlockParam.new(name) end |
#add_kw_opt_param(name, default_value) ⇒ Object
: (String name, String default_value) -> void
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
: (String name) -> void
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
: (String name) -> void
541 542 543 |
# File 'lib/rbi/model.rb', line 541 def add_kw_rest_param(name) params << KwRestParam.new(name) end |
#add_opt_param(name, default_value) ⇒ Object
: (String name, String default_value) -> void
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
: (String name) -> void
516 517 518 |
# File 'lib/rbi/model.rb', line 516 def add_param(name) params << ReqParam.new(name) end |
#add_rest_param(name) ⇒ Object
: (String name) -> void
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", is_abstract: false, is_override: false, is_overridable: false, is_final: false, type_params: [], checked: nil, &block) ⇒ Object
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 |
# File 'lib/rbi/model.rb', line 559 def add_sig( params: [], return_type: "void", 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, 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
: (Node other) -> bool
466 467 468 469 470 471 472 |
# File 'lib/rbi/rewriters/merge_trees.rb', line 466 def compatible_with?(other) other.is_a?(Method) && name == other.name && params == other.params && at_most_one_side_anonymous?(other) && (sigs.empty? || other.sigs.empty? || sigs == other.sigs) end |
#fully_qualified_name ⇒ Object
: -> String
585 586 587 588 589 590 591 |
# File 'lib/rbi/model.rb', line 585 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
: -> Array
114 115 116 |
# File 'lib/rbi/index.rb', line 114 def index_ids [fully_qualified_name] end |
#merge_with(other) ⇒ Object
: (Node other) -> void
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 |
# File 'lib/rbi/rewriters/merge_trees.rb', line 476 def merge_with(other) return unless other.is_a?(Method) super # If self is the all-anonymous side (since compatible_with? ensures # at most one side is), or if self has no sigs but other does, adopt # other's non-anonymous param names and sigs. if params.all?(&:anonymous?) || (sigs.empty? && !other.sigs.empty?) @params = other.params.dup @sigs = other.sigs.dup unless other.sigs.empty? return end other.sigs.each do |sig| sigs << sig unless sigs.include?(sig) end end |
#params ⇒ Object
: -> Array
459 460 461 |
# File 'lib/rbi/model.rb', line 459 def params @params ||= [] end |
#sigs? ⇒ Boolean
: -> bool
475 476 477 |
# File 'lib/rbi/model.rb', line 475 def sigs? !@sigs.nil? && !@sigs.empty? end |
#to_s ⇒ Object
: -> String
595 596 597 |
# File 'lib/rbi/model.rb', line 595 def to_s "#{fully_qualified_name}(#{params.join(", ")})" end |