class RuboCop::Cop::Style::OpMethod

This cop makes sure that certain operator methods have their sole parameter named `other`.

Constants

BLACKLISTED
MSG
OP_LIKE_METHODS
TARGET_ARGS

Public Instance Methods

on_def(node) click to toggle source
# File lib/rubocop/cop/style/op_method.rb, line 19
def on_def(node)
  name, args, _body = *node
  return unless op_method?(name) &&
                args.children.size == 1 &&
                !TARGET_ARGS.include?(args)

  add_offense(args.children[0], :expression, format(MSG, name))
end
op_method?(name) click to toggle source
# File lib/rubocop/cop/style/op_method.rb, line 28
def op_method?(name)
  return false if BLACKLISTED.include?(name)
  name !~ /\A\w/ || OP_LIKE_METHODS.include?(name)
end