Class: RBS::Inline::AST::Annotations::Method
- Defined in:
- lib/rbs/inline/ast/annotations.rb
Overview
‘@rbs METHOD-TYPE“
Instance Attribute Summary collapse
-
#method_type_source ⇒ Object
readonly
: String.
-
#method_types ⇒ Object
readonly
@rbs! type method_type = [MethodType, method_type?] | String.
-
#overloading ⇒ Object
readonly
‘true` if the method definition is overloading something.
-
#type ⇒ Object
readonly
: MethodType?.
Attributes inherited from Base
Instance Method Summary collapse
-
#construct_method_types(children) ⇒ Object
: (Array) -> method_type?.
- #each_method_type ⇒ Object
-
#error_source ⇒ Object
Returns the parsing error overload string.
-
#initialize(tree, source) ⇒ Method
constructor
A new instance of Method.
Constructor Details
#initialize(tree, source) ⇒ Method
Returns a new instance of Method.
614 615 616 617 618 619 620 621 |
# File 'lib/rbs/inline/ast/annotations.rb', line 614 def initialize(tree, source) @tree = tree @source = source overloads = tree.nth_tree!(1) @method_types = construct_method_types(overloads.non_trivia_trees.dup) @overloading = overloads.token?(:kDOT3, at: -1) end |
Instance Attribute Details
#method_type_source ⇒ Object (readonly)
: String
611 612 613 |
# File 'lib/rbs/inline/ast/annotations.rb', line 611 def method_type_source @method_type_source end |
#method_types ⇒ Object (readonly)
@rbs! type method_type = [MethodType, method_type?] | String
603 604 605 |
# File 'lib/rbs/inline/ast/annotations.rb', line 603 def method_types @method_types end |
#overloading ⇒ Object (readonly)
‘true` if the method definition is overloading something
607 608 609 |
# File 'lib/rbs/inline/ast/annotations.rb', line 607 def overloading @overloading end |
#type ⇒ Object (readonly)
: MethodType?
609 610 611 |
# File 'lib/rbs/inline/ast/annotations.rb', line 609 def type @type end |
Instance Method Details
#construct_method_types(children) ⇒ Object
: (Array) -> method_type?
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 |
# File 'lib/rbs/inline/ast/annotations.rb', line 624 def construct_method_types(children) first = children.shift case first when MethodType children.shift [ first, construct_method_types(children) ] when Array # `...` nil when AST::Tree # Syntax error first.to_s end end |
#each_method_type ⇒ Object
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 |
# File 'lib/rbs/inline/ast/annotations.rb', line 645 def each_method_type if block_given? type = self.method_types while true if type.is_a?(Array) yield type[0] type = type[1] else break end end else enum_for :each_method_type end end |
#error_source ⇒ Object
Returns the parsing error overload string
Returns ‘nil` if no parsing error found.
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 |
# File 'lib/rbs/inline/ast/annotations.rb', line 666 def error_source #: String? type = self.method_types while true if type.is_a?(Array) type = type[1] else break end end if type.is_a?(String) type end end |