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
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
# File 'lib/rbi/model.rb', line 412 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
403 404 405 |
# File 'lib/rbi/model.rb', line 403 def is_singleton @is_singleton end |
#name ⇒ Object
: String
397 398 399 |
# File 'lib/rbi/model.rb', line 397 def name @name end |
#params ⇒ Object (readonly)
: Array
400 401 402 |
# File 'lib/rbi/model.rb', line 400 def params @params end |
#visibility ⇒ Object
: Visibility
406 407 408 |
# File 'lib/rbi/model.rb', line 406 def visibility @visibility end |
Instance Method Details
#<<(param) ⇒ Object
: (Param param) -> void
432 433 434 |
# File 'lib/rbi/model.rb', line 432 def <<(param) @params << param end |
#add_block_param(name) ⇒ Object
: (String name) -> void
467 468 469 |
# File 'lib/rbi/model.rb', line 467 def add_block_param(name) @params << BlockParam.new(name) end |
#add_kw_opt_param(name, default_value) ⇒ Object
: (String name, String default_value) -> void
457 458 459 |
# File 'lib/rbi/model.rb', line 457 def add_kw_opt_param(name, default_value) @params << KwOptParam.new(name, default_value) end |
#add_kw_param(name) ⇒ Object
: (String name) -> void
452 453 454 |
# File 'lib/rbi/model.rb', line 452 def add_kw_param(name) @params << KwParam.new(name) end |
#add_kw_rest_param(name) ⇒ Object
: (String name) -> void
462 463 464 |
# File 'lib/rbi/model.rb', line 462 def add_kw_rest_param(name) @params << KwRestParam.new(name) end |
#add_opt_param(name, default_value) ⇒ Object
: (String name, String default_value) -> void
442 443 444 |
# File 'lib/rbi/model.rb', line 442 def add_opt_param(name, default_value) @params << OptParam.new(name, default_value) end |
#add_param(name) ⇒ Object
: (String name) -> void
437 438 439 |
# File 'lib/rbi/model.rb', line 437 def add_param(name) @params << ReqParam.new(name) end |
#add_rest_param(name) ⇒ Object
: (String name) -> void
447 448 449 |
# File 'lib/rbi/model.rb', line 447 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
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 |
# File 'lib/rbi/model.rb', line 472 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
440 441 442 443 444 445 446 |
# File 'lib/rbi/rewriters/merge_trees.rb', line 440 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
498 499 500 501 502 503 504 |
# File 'lib/rbi/model.rb', line 498 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
119 120 121 |
# File 'lib/rbi/index.rb', line 119 def index_ids [fully_qualified_name] end |
#merge_with(other) ⇒ Object
: (Node other) -> void
450 451 452 453 454 455 456 457 |
# File 'lib/rbi/rewriters/merge_trees.rb', line 450 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
508 509 510 |
# File 'lib/rbi/model.rb', line 508 def to_s "#{fully_qualified_name}(#{params.join(", ")})" end |