Class: RuboCop::Cop::Lint::Utils::NilReceiverChecker
- Inherits:
-
Object
- Object
- RuboCop::Cop::Lint::Utils::NilReceiverChecker
- 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
- #cant_be_nil? ⇒ Boolean
-
#initialize(receiver, additional_nil_methods) ⇒ NilReceiverChecker
constructor
A new instance of NilReceiverChecker.
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
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 |