class RuboCop::AST::DefNode

A node extension for `def` nodes. This will be used in place of a plain node when the builder constructs the AST, making its methods available to all `def` nodes within RuboCop.

Public Instance Methods

arguments() click to toggle source

An array containing the arguments of the method definition.

@return [Array<Node>] the arguments of the method definition

# File lib/rubocop/ast/node/def_node.rb, line 28
def arguments
  node_parts[1]
end
body() click to toggle source

The body of the method definition.

@note this can be either a `begin` node, if the method body contains

multiple expressions, or any other node, if it contains a single
expression.

@return [Node] the body of the method definition

# File lib/rubocop/ast/node/def_node.rb, line 39
def body
  node_parts[0]
end
method_name() click to toggle source

The name of the defined method as a symbol.

@return [Symbol] the name of the defined method

# File lib/rubocop/ast/node/def_node.rb, line 21
def method_name
  node_parts[2]
end
node_parts() click to toggle source

Custom destructuring method. This can be used to normalize destructuring for different variations of the node.

In this case, the `def` node destructures into:

`method_name, arguments, body`

while the `defs` node destructures into:

`receiver, method_name, arguments, body`

so we reverse the destructured array to get the optional receiver at the end, where it can be discarded.

@return [Array] the different parts of the `def` or `defs` node

# File lib/rubocop/ast/node/def_node.rb, line 65
def node_parts
  to_a.reverse
end
receiver() click to toggle source

The receiver of the method definition, if any.

@return [Node, nil] the receiver of the method definition, or `nil`.

# File lib/rubocop/ast/node/def_node.rb, line 46
def receiver
  node_parts[3]
end
void_context?() click to toggle source

Checks whether this node body is a void context.

@return [Boolean] whether the `def` node body is a void context

# File lib/rubocop/ast/node/def_node.rb, line 14
def void_context?
  method?(:initialize) || assignment_method?
end