Class: RuboCop::Cop::Gusto::NoSend

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/gusto/no_send.rb

Overview

Do not call a private method via __send__

Examples:

# bad
foo.__send__(:bar)
__send__(:run_baz)

# good
There's no better alternative, don't call private methods.

Constant Summary collapse

MSG =
"Do not call a private method via `__send__`."
RESTRICT_ON_SEND =
%i(__send__).freeze

Instance Method Summary collapse

Instance Method Details

#invoke_private_method_send?(node) ⇒ Object



21
22
23
# File 'lib/rubocop/cop/gusto/no_send.rb', line 21

def_node_matcher :invoke_private_method_send?, <<~PATTERN
  (call _ :__send__ (sym _))
PATTERN

#on_send(node) ⇒ Object Also known as: on_csend



25
26
27
# File 'lib/rubocop/cop/gusto/no_send.rb', line 25

def on_send(node)
  invoke_private_method_send?(node) { add_offense(node) }
end