Class: RuboCop::Cop::Style::CaseCorrector

Inherits:
Object
  • Object
show all
Extended by:
ConditionalAssignmentHelper
Defined in:
lib/rubocop/cop/style/conditional_assignment.rb

Overview

Corrector to correct conditional assignment in case statements.

Constant Summary

Constants included from ConditionalAssignmentHelper

RuboCop::Cop::Style::ConditionalAssignmentHelper::EQUAL

Class Method Summary collapse

Methods included from ConditionalAssignmentHelper

correct_branches, expand_elses, expand_when_branches, lhs, tail

Class Method Details

.correct(node) ⇒ Object



324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/rubocop/cop/style/conditional_assignment.rb', line 324

def correct(node)
  _condition, *when_branches, else_branch = *node
  else_branch = tail(else_branch)
  when_branches = expand_when_branches(when_branches)
  when_branches.map! { |when_branch| tail(when_branch) }
  _variable, *_operator, else_assignment = *else_branch

  lambda do |corrector|
    corrector.insert_before(node.source_range, lhs(else_branch))
    correct_branches(corrector, when_branches)
    corrector.replace(else_branch.source_range,
                      else_assignment.source)
  end
end