Why do we need to use if and? together, not just

what to use if and? together when you can use if you want in this case

unless person.present?

equivalently

if person.present
+5
source share
2 answers

They are not equivalent.

doSomeThing() unless person.present? will be executed only if person.presentthere isnull

doSomeThing() unless person.present will be executed if person.present- valuefalse

doSomeThing() if person.present will be executed if person.present- valuetrue

check compiled javascript .

+9
source

It is also possible that you give in to a typo in your question. Unless you have the attribute 'p er sent' on person, it will always be undefined, which is false.

+1
source

All Articles