class RBS
Represents an RBS type annotation following rbs-inline syntax.
Examples:
@rbs generic T- Declares a generic type parameter for a class@rbs [T] () { () -> T } -> Task[T]- Complete method type signature
Definitions
def self.parse(directive, text, lines, tags, level = 0)
Parse an RBS pragma from text.
Signature
-
parameter
directiveString The directive name (should be "rbs").
-
parameter
textString The RBS type annotation text.
-
parameter
linesArray(String) The remaining lines (not used for RBS).
-
parameter
tagsArray(Tag) The collection of tags.
-
parameter
levelInteger The indentation level.
Implementation
def self.parse(directive, text, lines, tags, level = 0)
self.build(directive, text)
end
def self.build(directive, text)
Build an RBS pragma from a directive and text.
Signature
-
parameter
directiveString The directive name.
-
parameter
textString The RBS type annotation text.
Implementation
def self.build(directive, text)
node = self.new(directive, text)
return node
end
def initialize(directive, text)
Initialize a new RBS pragma.
Signature
-
parameter
directiveString The directive name.
-
parameter
textString? The RBS type annotation text.
Implementation
def initialize(directive, text)
super(directive)
@text = text&.strip || ""
end
attr :text
The RBS type annotation text.
Signature
-
attribute
String The raw RBS text.
def generic?
Check if this is a generic type declaration.
Signature
-
returns
bool True if this is a generic declaration.
Implementation
def generic?
@text.start_with?("generic ")
end
def generic_parameter
Extract the generic type parameter name.
Signature
-
returns
String? The generic type parameter name, or nil if not a generic.
Implementation
def generic_parameter
if generic?
# Extract the parameter name from "generic T" or "generic T, U"
match = @text.match(/^generic\s+([A-Z][A-Za-z0-9_]*(?:\s*,\s*[A-Z][A-Za-z0-9_]*)*)/)
return match[1] if match
end
end
def method_signature?
Check if this is a method type signature.
Signature
-
returns
bool True if this is a method signature.
Implementation
def method_signature?
@text && !generic?
end
def method_signature
Get the method type signature text.
Signature
-
returns
String? The method signature text, or nil if not a method signature.
Implementation
def method_signature
method_signature? ? @text : nil
end