G33K-TRICKS: How to solve "Move`% s` out of conditional. " error.

Monday, October 9, 2017

How to solve "Move`% s` out of conditional. " error.


[SOLVED] How to deal with "Move `% s` out of conditional." error from Rubocop.

Below is the problem statement.
Problem:
Move `% s` out of the conditional.

where %s is a Method name.
As the method call pointed out that %s is redundant, Rubocop throws this as an error.
What it means is that the method that is common under both condition should be moved outside the Conditions as it would be executed in either of case.
Below the simpler way to look at it and how to resolve it.
Solution:
@bad Code
if condition
  do_x
  do_z
else
  do_y
  do_z
end

@good Code
if condition
  do_x
else
  do_y
end
do_z 

1 comment:

شركة المثالي سوبر said...
This comment has been removed by a blog administrator.