Class: YARD::Parser::RBS::Statement

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_typeString? (readonly)

Returns RBS type annotation for attrs and constants.

Returns:

  • (String, nil)

    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

#blockArray<Statement> (readonly)

Returns child statements for namespace blocks.

Returns:



37
38
39
# File 'lib/yard/parser/rbs/statement.rb', line 37

def block
  @block
end

#commentsString? (readonly)

Returns adjacent comment text (the docstring).

Returns:

  • (String, nil)

    adjacent comment text (the docstring)



28
29
30
# File 'lib/yard/parser/rbs/statement.rb', line 28

def comments
  @comments
end

#comments_hash_flagfalse (readonly)

Returns RBS files don’t use ## hash-flag comments.

Returns:

  • (false)

    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_rangeRange? (readonly)

Returns line range of the preceding comments.

Returns:

  • (Range, nil)

    line range of the preceding comments



31
32
33
# File 'lib/yard/parser/rbs/statement.rb', line 31

def comments_range
  @comments_range
end

#lineInteger (readonly)

Returns 1-indexed line number of this statement.

Returns:

  • (Integer)

    1-indexed line number of this statement



22
23
24
# File 'lib/yard/parser/rbs/statement.rb', line 22

def line
  @line
end

#mixin_nameString? (readonly)

Returns mixin name for :include/:extend/:prepend.

Returns:

  • (String, nil)

    mixin name for :include/:extend/:prepend



44
45
46
# File 'lib/yard/parser/rbs/statement.rb', line 44

def mixin_name
  @mixin_name
end

#nameString (readonly)

Returns the declaration name.

Returns:

  • (String)

    the declaration name



16
17
18
# File 'lib/yard/parser/rbs/statement.rb', line 16

def name
  @name
end

#signaturesArray<String> (readonly)

Returns RBS type signature strings for :method_def Each element is one overload (e.g. “(String name) -> Integer”).

Returns:

  • (Array<String>)

    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

#sourceString (readonly)

Returns raw source text of the statement.

Returns:

  • (String)

    raw source text of the statement



25
26
27
# File 'lib/yard/parser/rbs/statement.rb', line 25

def source
  @source
end

#superclassString? (readonly)

Returns the superclass name (for :class).

Returns:

  • (String, nil)

    the superclass name (for :class)



19
20
21
# File 'lib/yard/parser/rbs/statement.rb', line 19

def superclass
  @superclass
end

#typeSymbol (readonly)

Returns declaration type: :class, :module, :interface, :method_def, :attr_reader, :attr_writer, :attr_accessor, :include, :extend, :prepend, :constant, :alias.

Returns:

  • (Symbol)

    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

#visibilitySymbol? (readonly)

Returns :class or :instance scope hint from parser.

Returns:

  • (Symbol, nil)

    :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

#showString

Returns a textual snippet used in error messages.

Returns:

  • (String)

    a textual snippet used in error messages



69
70
71
# File 'lib/yard/parser/rbs/statement.rb', line 69

def show
  source
end