module RuboCop::Cop::OnMethodDef

Common functionality for checking instance methods and singleton methods.

Public Instance Methods

on_def(node) click to toggle source
# File lib/rubocop/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/rubocop/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/rubocop/cop/mixin/on_method_def.rb, line 22
def modifier_and_def_on_same_line?(send_node)
  send_node.receiver.nil? &&
    send_node.method_name != :def &&
    send_node.method_args.size == 1 &&
    [:def, :defs].include?(send_node.method_args.first.type)
end