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



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

def name
  parse_def!

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

#parametersObject

Parses the parameters from the @def annotations in the docstring



127
128
129
130
131
# File 'lib/yard-rustdoc/statements.rb', line 127

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.



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/yard-rustdoc/statements.rb', line 108

def scope
  inputs =
    # JSON rustdoc FORMAT_VERSION < 34
    @rustdoc.dig("inner", "function", "decl", "inputs") ||
    # >= 34
    @rustdoc.dig("inner", "function", "sig", "inputs")

  arg_names = 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