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
1.4m articles
1.4m replys
5 comments
57.0k users