class RuboCop::Cop::Style::DefWithParentheses

Checks for parentheses in the definition of a method, that does not take any arguments. Both instance and class/singleton methods are checked.

@example

# bad
def foo()
  do_something
end

# good
def foo
  do_something
end

# bad
def foo() = do_something

# good
def foo = do_something

# good (without parentheses it's a syntax error)
def foo() do_something end

@example

# bad
def Baz.foo()
  do_something
end

# good
def Baz.foo
  do_something
end

Constants

MSG

Public Instance Methods

on_def(node) click to toggle source
# File lib/rubocop/cop/style/def_with_parentheses.rb, line 47
def on_def(node)
  return if node.single_line? && !node.endless?
  return unless !node.arguments? && (node_arguments = node.arguments.source_range)

  add_offense(node_arguments) do |corrector|
    corrector.remove(node_arguments)
  end
end
Also aliased as: on_defs
on_defs(node)
Alias for: on_def