Class: RuboCop::Cop::G2::PredicateMemoization

Inherits:
Cop
  • Object
show all
Defined in:
lib/rubocop/cop/g2/predicate_memoization.rb

Constant Summary collapse

MSG =
'Do not use `@foo ||= bar` to memoize predicate methods, since `false` or `nil` return values will not'\
' be memoized with this approach.'.freeze

Instance Method Summary collapse

Instance Method Details

#on_def(node) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/rubocop/cop/g2/predicate_memoization.rb', line 8

def on_def(node)
  return unless predicate_method?(node)

  offending_nodes(node).each do |offender|
    add_offense(offender, location: :expression)
  end
end