Class: RuboCop::Cop::Betterment::MemoizationWithArguments

Inherits:
RuboCop::Cop
  • Object
show all
Defined in:
lib/rubocop/cop/betterment/memoization_with_arguments.rb

Constant Summary collapse

MSG =
'Memoized method `%<method>s` accepts arguments, ' \
'which may cause it to return a stale result. ' \
'Remove memoization or refactor to remove arguments.'

Instance Method Summary collapse

Instance Method Details

#on_def(node) ⇒ Object Also known as: on_defs



24
25
26
27
28
29
30
# File 'lib/rubocop/cop/betterment/memoization_with_arguments.rb', line 24

def on_def(node)
  (method_name, ivar_assign) = memoized?(node)
  return if ivar_assign.nil? || node.arguments.empty? || method_name == :initialize

  msg = format(MSG, method: method_name)
  add_offense(node, location: ivar_assign.source_range, message: msg)
end