Class: Decode::Comment::RBS
Overview
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` - Complete method type signature
Constant Summary
Constants inherited from Tag
Instance Attribute Summary collapse
-
#text ⇒ Object
readonly
The RBS type annotation text.
-
#The raw RBS text.(rawRBStext.) ⇒ Object
readonly
The RBS type annotation text.
Attributes inherited from Tag
#The directive that generated the tag., #directive
Attributes inherited from Node
#The children of this node., #children
Class Method Summary collapse
-
.build(directive, text) ⇒ Object
Build an RBS pragma from a directive and text.
-
.parse(directive, text, lines, tags, level = 0) ⇒ Object
Parse an RBS pragma from text.
Instance Method Summary collapse
-
#generic? ⇒ Boolean
Check if this is a generic type declaration.
-
#generic_parameter ⇒ Object
Extract the generic type parameter name.
-
#initialize(directive, text) ⇒ RBS
constructor
Initialize a new RBS pragma.
-
#method_signature ⇒ Object
Get the method type signature text.
-
#method_signature? ⇒ Boolean
Check if this is a method type signature.
Methods inherited from Tag
Methods inherited from Node
#add, #children?, #each, #filter, #traverse
Constructor Details
#initialize(directive, text) ⇒ RBS
Initialize a new RBS pragma.
38 39 40 41 |
# File 'lib/decode/comment/rbs.rb', line 38 def initialize(directive, text) super(directive) @text = text&.strip || "" end |
Instance Attribute Details
#text ⇒ Object (readonly)
The RBS type annotation text.
45 46 47 |
# File 'lib/decode/comment/rbs.rb', line 45 def text @text end |
#The raw RBS text.(rawRBStext.) ⇒ Object (readonly)
The RBS type annotation text.
45 |
# File 'lib/decode/comment/rbs.rb', line 45 attr :text |
Class Method Details
.build(directive, text) ⇒ Object
Build an RBS pragma from a directive and text.
30 31 32 33 |
# File 'lib/decode/comment/rbs.rb', line 30 def self.build(directive, text) node = self.new(directive, text) return node end |
.parse(directive, text, lines, tags, level = 0) ⇒ Object
Parse an RBS pragma from text.
23 24 25 |
# File 'lib/decode/comment/rbs.rb', line 23 def self.parse(directive, text, lines, , level = 0) self.build(directive, text) end |
Instance Method Details
#generic? ⇒ Boolean
Check if this is a generic type declaration.
49 50 51 |
# File 'lib/decode/comment/rbs.rb', line 49 def generic? @text.start_with?("generic ") end |
#generic_parameter ⇒ Object
Extract the generic type parameter name.
55 56 57 58 59 60 61 |
# File 'lib/decode/comment/rbs.rb', line 55 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 |
#method_signature ⇒ Object
Get the method type signature text.
71 72 73 |
# File 'lib/decode/comment/rbs.rb', line 71 def method_signature method_signature? ? @text : nil end |
#method_signature? ⇒ Boolean
Check if this is a method type signature.
65 66 67 |
# File 'lib/decode/comment/rbs.rb', line 65 def method_signature? @text && !generic? end |