I have the following line of code :
if params[:"available_#{district.id}"] == 'true'
@deliverycharge = @product.deliverycharges.create!(districtrate_id: district.id)
delivery_custom_price(district)
end
Rubocop highlight it and asks me to use a guard clause for it. How can I do it?
EDIT : Rubocop highlighted the first line and gave this message Use a guard clause instead of wrapping the code inside a conditional expression
Don't know what the surrounding code looks like so let's assume your code is the entire body of a method. Then a guard clause might look like this:
def some_method
return if params[:"available_#{district.id}"] != 'true' #guard clause
@deliverycharge = @product.deliverycharges.create!(districtrate_id: district.id)
delivery_custom_price(district)
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With