class SyntaxTree::Parser

def on_defs(target, operator, name, params, bodystmt)

Experimental RBS support (using type sampling data from the type_fusion project).

def on_defs: (SyntaxTree::VarRef target, SyntaxTree::Period operator, SyntaxTree::Ident name, SyntaxTree::Paren params, SyntaxTree::BodyStmt bodystmt) -> untyped

This signature was generated using 1 sample from 1 application.

) -> DefNode
BodyStmt bodystmt
(Params | Paren) params,
(Backtick | Const | Ident | Kw | Op) name,
(Op | Period) operator,
untyped target,
on_defs: (
:call-seq:
def on_defs(target, operator, name, params, bodystmt)
  # Make sure to delete this token in case you're defining something
  # like def class which would lead to this being a kw and causing all kinds
  # of trouble
  tokens.delete(name)
  # If there aren't any params then we need to correct the params node
  # location information
  if params.is_a?(Params) && params.empty?
    end_char = name.location.end_char
    end_column = name.location.end_column
    location =
      Location.new(
        start_line: params.location.start_line,
        start_char: end_char,
        start_column: end_column,
        end_line: params.location.end_line,
        end_char: end_char,
        end_column: end_column
      )
    params = Params.new(location: location)
  end
  beginning = consume_keyword(:def)
  ending = find_keyword(:end)
  if ending
    tokens.delete(ending)
    start_char = find_next_statement_start(params.location.end_char)
    bodystmt.bind(
      self,
      start_char,
      start_char - line_counts[params.location.start_line - 1].start,
      ending.location.start_char,
      ending.location.start_column
    )
    DefNode.new(
      target: target,
      operator: operator,
      name: name,
      params: params,
      bodystmt: bodystmt,
      location: beginning.location.to(ending.location)
    )
  else
    # In Ruby >= 3.1.0, this is a BodyStmt that wraps a single statement in
    # the statements list. Before, it was just the individual statement.
    statement = bodystmt.is_a?(BodyStmt) ? bodystmt.statements : bodystmt
    DefNode.new(
      target: target,
      operator: operator,
      name: name,
      params: params,
      bodystmt: statement,
      location: beginning.location.to(bodystmt.location)
    )
  end
end