Class: RuboCop::Cop::Lint::Utils::NilReceiverChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/cop/lint/utils/nil_receiver_checker.rb

Overview

Utility class that checks if the receiver can’t be nil.

Constant Summary collapse

NIL_METHODS =
(nil.methods + %i[!]).to_set.freeze

Instance Method Summary collapse

Constructor Details

#initialize(receiver, additional_nil_methods) ⇒ NilReceiverChecker

Returns a new instance of NilReceiverChecker.



11
12
13
14
15
# File 'lib/rubocop/cop/lint/utils/nil_receiver_checker.rb', line 11

def initialize(receiver, additional_nil_methods)
  @receiver = receiver
  @additional_nil_methods = additional_nil_methods
  @checked_nodes = {}.compare_by_identity
end

Instance Method Details

#cant_be_nil?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/rubocop/cop/lint/utils/nil_receiver_checker.rb', line 17

def cant_be_nil?
  sole_condition_of_parent_if?(@receiver) || _cant_be_nil?(@receiver.parent, @receiver)
end