5 ms·
That’s exactly how I use ‘unless’. Simple on condition (no else branch) use cases in one liners, anything more complex, I move to if. Best of both world I’d say
by roboben 4y ago
That’s exactly how I use ‘unless’. Simple on condition (no else branch) use cases in one liners, anything more complex, I move to if. Best of both world I’d say!
- aqme28 4y agoThat’s the generally recommended style! I hate this post. It’s arguing against something that is well known to be a bad practice (that’s fine), but it seems to put the fault for this on Ruby itself.
- JeremyNT 4y agoYes! And rubocop can encourage the use of 'unless' in only these simple situations where it does enhance legibility. https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/UnlessElse https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/Unle... https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/UnlessLogicalOperators https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/Unle...