class RuboCop::Cop::Lint::NoReturnInBeginEndBlocks
Checks for the presence of a ‘return` inside a `begin..end` block in assignment contexts. In this situation, the `return` will result in an exit from the current method, possibly leading to unexpected behavior.
@example
# bad @some_variable ||= begin return some_value if some_condition_is_met do_something end
@example
# good @some_variable ||= begin if some_condition_is_met some_value else do_something end end # good some_variable = if some_condition_is_met return if another_condition_is_met some_value else do_something end
Constants
- MSG
Public Instance Methods
on_lvasgn(node)
click to toggle source
# File lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb, line 46 def on_lvasgn(node) node.each_node(:kwbegin) do |kwbegin_node| kwbegin_node.each_node(:return) do |return_node| add_offense(return_node) end end end
Also aliased as: on_or_asgn, on_op_asgn