Can anyone explain me the difference between if and unless and when to use it?
if
unless
unless is just a negated if. That is, it executes whatever it contains if the condition is not true.
unless foo? # blabla end
Simply means
if !foo? # blabla end
It's all a matter of what you find easier to read, really.
See also: Unless, The Abused Ruby Conditional
2.1m questions
2.1m answers
60 comments
57.0k users