DecodeSourceDecodeCommentRBS

class RBS

Represents an RBS type annotation following rbs-inline syntax.

Examples:

Definitions

def self.parse(directive, text, lines, tags, level = 0)

Parse an RBS pragma from text.

Signature

parameter directive String

The directive name (should be "rbs").

parameter text String

The RBS type annotation text.

parameter lines Array(String)

The remaining lines (not used for RBS).

parameter tags Array(Tag)

The collection of tags.

parameter level Integer

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 directive String

The directive name.

parameter text String

The RBS type annotation text.

Implementation

def self.build(directive, text)
	node = self.new(directive, text)
	return node
end

def initialize(directive, text = nil)

Initialize a new RBS pragma.

Signature

parameter directive String

The directive name.

parameter text String

The RBS type annotation text.

Implementation

def initialize(directive, text = nil)
	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 Boolean

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 | Nil

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 Boolean

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 | Nil

The method signature text, or nil if not a method signature.

Implementation

def method_signature
	method_signature? ? @text : nil
end