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
: String.
-
#params ⇒ Object
readonly
: Array.
-
#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: [], is_singleton: false, visibility: Public.new, sigs: [], loc: nil, comments: [], &block) ⇒ Method constructor
-
#merge_with(other) ⇒ Object
: (Node other) -> void.
-
#to_s ⇒ Object
: -> String.
Methods inherited from NodeWithComments
#annotations, #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: [], is_singleton: false, visibility: Public.new, sigs: [], loc: nil, comments: [], &block) ⇒ Method
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 |
# File 'lib/rbi/model.rb', line 442 def initialize( name, params: [], is_singleton: false, visibility: Public.new, sigs: [], loc: nil, comments: [], &block ) super(loc: loc, comments: comments) @name = name @params = params @is_singleton = is_singleton @visibility = visibility @sigs = sigs block&.call(self) end |
Instance Attribute Details
#is_singleton ⇒ Object
: bool
425 426 427 |
# File 'lib/rbi/model.rb', line 425 def is_singleton @is_singleton end |
#name ⇒ Object
: String
419 420 421 |
# File 'lib/rbi/model.rb', line 419 def name @name end |
#params ⇒ Object (readonly)
: Array
422 423 424 |
# File 'lib/rbi/model.rb', line 422 def params @params end |
#visibility ⇒ Object
: Visibility
428 429 430 |
# File 'lib/rbi/model.rb', line 428 def visibility @visibility end |
Instance Method Details
#<<(param) ⇒ Object
: (Param param) -> void
462 463 464 |
# File 'lib/rbi/model.rb', line 462 def <<(param) @params << param end |
#add_block_param(name) ⇒ Object
: (String name) -> void
497 498 499 |
# File 'lib/rbi/model.rb', line 497 def add_block_param(name) @params << BlockParam.new(name) end |
#add_kw_opt_param(name, default_value) ⇒ Object
: (String name, String default_value) -> void
487 488 489 |
# File 'lib/rbi/model.rb', line 487 def add_kw_opt_param(name, default_value) @params << KwOptParam.new(name, default_value) end |
#add_kw_param(name) ⇒ Object
: (String name) -> void
482 483 484 |
# File 'lib/rbi/model.rb', line 482 def add_kw_param(name) @params << KwParam.new(name) end |
#add_kw_rest_param(name) ⇒ Object
: (String name) -> void
492 493 494 |
# File 'lib/rbi/model.rb', line 492 def add_kw_rest_param(name) @params << KwRestParam.new(name) end |
#add_opt_param(name, default_value) ⇒ Object
: (String name, String default_value) -> void
472 473 474 |
# File 'lib/rbi/model.rb', line 472 def add_opt_param(name, default_value) @params << OptParam.new(name, default_value) end |
#add_param(name) ⇒ Object
: (String name) -> void
467 468 469 |
# File 'lib/rbi/model.rb', line 467 def add_param(name) @params << ReqParam.new(name) end |
#add_rest_param(name) ⇒ Object
: (String name) -> void
477 478 479 |
# File 'lib/rbi/model.rb', line 477 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
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 |
# File 'lib/rbi/model.rb', line 510 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
453 454 455 456 457 458 459 |
# 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
: -> String
536 537 538 539 540 541 542 |
# File 'lib/rbi/model.rb', line 536 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
463 464 465 466 467 468 469 470 |
# File 'lib/rbi/rewriters/merge_trees.rb', line 463 def merge_with(other) return unless other.is_a?(Method) super other.sigs.each do |sig| sigs << sig unless sigs.include?(sig) end end |
#to_s ⇒ Object
: -> String
546 547 548 |
# File 'lib/rbi/model.rb', line 546 def to_s "#{fully_qualified_name}(#{params.join(", ")})" end |