Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

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

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


Problem:

Move `% s` out of the Conditional.

where %s is a Method 

As the method call pointed out at %s is redundant, Rubocop throws this as Error. The method that is common under both condition should be moved outside the Conditions as it would be executed in either of case.
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


This post first appeared on G33K-TRICKS - Your Source To Tips And Tricks, please read the originial post: here

Share the post

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

×

Subscribe to G33k-tricks - Your Source To Tips And Tricks

Get updates delivered right to your inbox!

Thank you for your subscription

×