Class: YARD::Parser::RBS::Statement
- Inherits:
-
Object
- Object
- YARD::Parser::RBS::Statement
- Defined in:
- lib/yard/parser/rbs/statement.rb
Overview
Represents a single parsed declaration from an RBS file. Each Statement may have a block of child statements for namespace declarations (class, module, interface).
Instance Attribute Summary collapse
-
#attr_rbs_type ⇒ String?
readonly
RBS type annotation for attrs and constants.
-
#block ⇒ Array<Statement>
readonly
Child statements for namespace blocks.
-
#comments ⇒ String?
readonly
Adjacent comment text (the docstring).
-
#comments_hash_flag ⇒ false
readonly
RBS files don’t use ## hash-flag comments.
-
#comments_range ⇒ Range?
readonly
Line range of the preceding comments.
-
#line ⇒ Integer
readonly
1-indexed line number of this statement.
-
#mixin_name ⇒ String?
readonly
Mixin name for :include/:extend/:prepend.
-
#name ⇒ String
readonly
The declaration name.
-
#signatures ⇒ Array<String>
readonly
RBS type signature strings for :method_def Each element is one overload (e.g. “(String name) -> Integer”).
-
#source ⇒ String
readonly
Raw source text of the statement.
-
#superclass ⇒ String?
readonly
The superclass name (for :class).
-
#type ⇒ Symbol
readonly
Declaration type: :class, :module, :interface, :method_def, :attr_reader, :attr_writer, :attr_accessor, :include, :extend, :prepend, :constant, :alias.
-
#visibility ⇒ Symbol?
readonly
:class or :instance scope hint from parser.
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ Statement
constructor
A new instance of Statement.
-
#show ⇒ String
A textual snippet used in error messages.
Constructor Details
#initialize(attrs = {}) ⇒ Statement
Returns a new instance of Statement.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/yard/parser/rbs/statement.rb', line 52 def initialize(attrs = {}) @type = attrs[:type] @name = attrs[:name] @superclass = attrs[:superclass] @line = attrs[:line] || 1 @source = attrs[:source] || '' @comments = attrs[:comments] @comments_range = attrs[:comments_range] @comments_hash_flag = false @block = attrs[:block] || [] @signatures = attrs[:signatures] || [] @mixin_name = attrs[:mixin_name] @attr_rbs_type = attrs[:attr_rbs_type] @visibility = attrs[:visibility] end |
Instance Attribute Details
#attr_rbs_type ⇒ String? (readonly)
Returns RBS type annotation for attrs and constants.
47 48 49 |
# File 'lib/yard/parser/rbs/statement.rb', line 47 def attr_rbs_type @attr_rbs_type end |
#block ⇒ Array<Statement> (readonly)
Returns child statements for namespace blocks.
37 38 39 |
# File 'lib/yard/parser/rbs/statement.rb', line 37 def block @block end |
#comments ⇒ String? (readonly)
Returns adjacent comment text (the docstring).
28 29 30 |
# File 'lib/yard/parser/rbs/statement.rb', line 28 def comments @comments end |
#comments_hash_flag ⇒ false (readonly)
Returns RBS files don’t use ## hash-flag comments.
34 35 36 |
# File 'lib/yard/parser/rbs/statement.rb', line 34 def comments_hash_flag @comments_hash_flag end |
#comments_range ⇒ Range? (readonly)
Returns line range of the preceding comments.
31 32 33 |
# File 'lib/yard/parser/rbs/statement.rb', line 31 def comments_range @comments_range end |
#line ⇒ Integer (readonly)
Returns 1-indexed line number of this statement.
22 23 24 |
# File 'lib/yard/parser/rbs/statement.rb', line 22 def line @line end |
#mixin_name ⇒ String? (readonly)
Returns mixin name for :include/:extend/:prepend.
44 45 46 |
# File 'lib/yard/parser/rbs/statement.rb', line 44 def mixin_name @mixin_name end |
#name ⇒ String (readonly)
Returns the declaration name.
16 17 18 |
# File 'lib/yard/parser/rbs/statement.rb', line 16 def name @name end |
#signatures ⇒ Array<String> (readonly)
Returns RBS type signature strings for :method_def Each element is one overload (e.g. “(String name) -> Integer”).
41 42 43 |
# File 'lib/yard/parser/rbs/statement.rb', line 41 def signatures @signatures end |
#source ⇒ String (readonly)
Returns raw source text of the statement.
25 26 27 |
# File 'lib/yard/parser/rbs/statement.rb', line 25 def source @source end |
#superclass ⇒ String? (readonly)
Returns the superclass name (for :class).
19 20 21 |
# File 'lib/yard/parser/rbs/statement.rb', line 19 def superclass @superclass end |
#type ⇒ Symbol (readonly)
Returns declaration type: :class, :module, :interface, :method_def, :attr_reader, :attr_writer, :attr_accessor, :include, :extend, :prepend, :constant, :alias.
13 14 15 |
# File 'lib/yard/parser/rbs/statement.rb', line 13 def type @type end |
#visibility ⇒ Symbol? (readonly)
Returns :class or :instance scope hint from parser.
50 51 52 |
# File 'lib/yard/parser/rbs/statement.rb', line 50 def visibility @visibility end |
Instance Method Details
#show ⇒ String
Returns a textual snippet used in error messages.
69 70 71 |
# File 'lib/yard/parser/rbs/statement.rb', line 69 def show source end |