module RubbyCop::Cop::OnMethodDef

Common functionality for checking instance methods and singleton methods.

Public Instance Methods

method_def_node_parts(node) click to toggle source

This method provides scope agnostic method node destructuring by moving the scope to the end where it can easily be ignored.

# File lib/rubbycop/cop/mixin/on_method_def.rb, line 19
def method_def_node_parts(node)
  if node.def_type?
    method_name, args, body = *node
  elsif node.defs_type?
    scope, method_name, args, body = *node
  else
    return []
  end

  [method_name, args, body, scope]
end
on_def(node) click to toggle source
# File lib/rubbycop/cop/mixin/on_method_def.rb, line 7
def on_def(node)
  method_name, args, body = *node
  on_method_def(node, method_name, args, body)
end
on_defs(node) click to toggle source
# File lib/rubbycop/cop/mixin/on_method_def.rb, line 12
def on_defs(node)
  _scope, method_name, args, body = *node
  on_method_def(node, method_name, args, body)
end

Private Instance Methods

modifier_and_def_on_same_line?(send_node) click to toggle source

Returns true for constructs such as private def my_method which are allowed in Ruby 2.1 and later.

# File lib/rubbycop/cop/mixin/on_method_def.rb, line 36
def modifier_and_def_on_same_line?(send_node)
  !send_node.receiver &&
    send_node.method_name != :def &&
    send_node.arguments.one? &&
    %i[def defs].include?(send_node.first_argument.type)
end