Latest Tweets:
I am a Scottish graphic designer and programmer with over 10 years experience in the industry. I am versed in both design and development giving me a very well-rounded skill set that allows me to fully realise your idea and put it to life.
I own a web development agency based in Central London, UK.
Ask me anything | Submit | Archive | RSS
This is a very small tip aimed for people to clean up their code-base and remove some of the double negatives.
Often I shall see:
unless @user.nil?
The issue with this is approach is that unless is harder to read than if, then you have to mentally process the #nil?
The other approach is:
if @user
However, for a lot of people this is not explicit enough. I find that too few know about #present? method
if @user.present?
#present? is literally the opposite of #blank? and thus checks if it is not nil? or if it is not empty?
Hopefully with this small tidbit of knowledge, you can clean up your code and make it easier to read.