Class: RuboCop::Cop::Lint::NoReturnInMemoization
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Lint::NoReturnInMemoization
- Defined in:
- lib/rubocop/cop/lint/no_return_in_memoization.rb
Overview
Checks for the use of a return with a value in begin..end blocks
in the context of instance variable assignment such as memoization.
Using return with a value in these blocks can lead to unexpected behavior
as the return will exit the method that contains and not set the values
of the instance variable.
Constant Summary collapse
- MSG =
"Do not `return` in `begin..end` blocks in instance variable assignment contexts."
Instance Method Summary collapse
- #on_op_asgn(node) ⇒ Object
- #on_or_asgn(node) ⇒ Object (also: #on_ivasgn, #on_and_asgn)
Instance Method Details
#on_op_asgn(node) ⇒ Object
87 88 89 90 91 |
# File 'lib/rubocop/cop/lint/no_return_in_memoization.rb', line 87 def on_op_asgn(node) return unless node.assignment_node.ivasgn_type? on_or_asgn(node) end |
#on_or_asgn(node) ⇒ Object Also known as: on_ivasgn, on_and_asgn
79 80 81 82 83 84 85 |
# File 'lib/rubocop/cop/lint/no_return_in_memoization.rb', line 79 def on_or_asgn(node) node.each_node(:kwbegin) do |kwbegin_node| kwbegin_node.each_node(:return) do |return_node| add_offense(return_node) end end end |