Class: RuboCop::Sorbet::RBSParser::Signature
- Inherits:
-
Object
- Object
- RuboCop::Sorbet::RBSParser::Signature
- Defined in:
- lib/rubocop/sorbet/rbs_parser.rb
Overview
One RBS signature (a #: line plus any #| continuation lines).
Encapsulates the parsed structure so callers query the signature rather
than re-parsing comments through the module.
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
Returns the value of attribute comments.
Instance Method Summary collapse
-
#initialize(processed_source, comments) ⇒ Signature
constructor
A new instance of Signature.
-
#return_type ⇒ Object
The return type expression as a string (e.g.
"String","void","^(Integer) -> void","Integer | String"), or nil if the signature has no return arrow or an empty return. -
#return_type_range ⇒ Object
[highlight_range, replace_range]covering the return type expression, or nil if there is no return type. -
#void? ⇒ Boolean
True if the signature declares a
voidreturn type.
Constructor Details
#initialize(processed_source, comments) ⇒ Signature
Returns a new instance of Signature.
78 79 80 81 |
# File 'lib/rubocop/sorbet/rbs_parser.rb', line 78 def initialize(processed_source, comments) @processed_source = processed_source @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
Returns the value of attribute comments.
76 77 78 |
# File 'lib/rubocop/sorbet/rbs_parser.rb', line 76 def comments @comments end |
Instance Method Details
#return_type ⇒ Object
The return type expression as a string (e.g. "String", "void",
"^(Integer) -> void", "Integer | String"), or nil if the
signature has no return arrow or an empty return.
86 87 88 |
# File 'lib/rubocop/sorbet/rbs_parser.rb', line 86 def return_type parsed[:expr] end |
#return_type_range ⇒ Object
[highlight_range, replace_range] covering the return type
expression, or nil if there is no return type. highlight_range
covers the first token (which may span #| lines); replace_range
covers the entire return expression.
94 95 96 97 98 |
# File 'lib/rubocop/sorbet/rbs_parser.rb', line 94 def return_type_range return unless parsed[:expr] [parsed[:highlight], parsed[:replace]] end |
#void? ⇒ Boolean
True if the signature declares a void return type.
101 102 103 |
# File 'lib/rubocop/sorbet/rbs_parser.rb', line 101 def void? return_type == "void" end |