Ruby: unless vs if not

I hope this helps you: https://github.com/rubocop-hq/ruby-style-guide#if-vs-unless

Prefer unless over if for negative conditions (or control flow ||).

# bad
do_something if !some_condition

# bad
do_something if not some_condition

# good
do_something unless some_condition

I personally agree with what’s written there choosing unless something over if !something for modifiers and simple ones and when there’s an else prefer if.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)