Im refactoring my older code parts, have lots of returns with multi line like:
if ...
return false
else
return true
end
How could one refactor to use a single line and return true or false?
Say foo is what is on the right of your if, then you can replace with:
foo ? false : true
This is known as the ternary operator.
Notice that in your case you could simply do:
!foo
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