2 ms·
IMHO, 'unless' in Ruby works best for single checks. It's just a convenient form of 'if not'. That's about it. I always insist on not using 'unless' if it's no
by thunderbong 4y ago
IMHO, 'unless' in Ruby works best for single checks. It's just a convenient form of 'if not'. That's about it.
I always insist on not using 'unless' if it's not clearly readable as an english phrase or if there's an 'else' as well.
A similar pattern I follow with 'if !'. If there's an 'else' condition always put the positive check first and the negative one in the else, rather than the other way around.
Footguns are equally possible using complex 'if !' statements.