Class: YARD::Parser::Rustdoc::Statements::Method

Inherits:
Base
  • Object
show all
Defined in:
lib/yard-rustdoc/statements.rb

Instance Method Summary collapse

Methods inherited from Base

#comments_hash_flag, #comments_range, #docstring, #file, #initialize, #line, #line_range, #show, #source

Constructor Details

This class inherits a constructor from YARD::Parser::Rustdoc::Statements::Base

Instance Method Details

#nameObject



98
99
100
101
102
# File 'lib/yard-rustdoc/statements.rb', line 98

def name
  parse_def!

  @name || @rustdoc.fetch("name")
end

#parametersObject

Parses the parameters from the @def annotations in the docstring



120
121
122
123
124
# File 'lib/yard-rustdoc/statements.rb', line 120

def parameters
  parse_def!

  @parameters
end

#scopeObject

Infers the scope (instance vs class) based on the usage of “self” or “rb_self” as an arg name.



106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/yard-rustdoc/statements.rb', line 106

def scope
  arg_names = @rustdoc
    .dig("inner", "function", "decl", "inputs")
    .map(&:first)
    .slice(0, 2) # Magnus may inject a Ruby handle as arg0, hence we check 2 args

  if arg_names.include?("self") || arg_names.include?("rb_self")
    :instance
  else
    :class
  end
end