Is there a Ruby, or Ruby-ism for not_nil? opposite of nil? method?

You seem overly concerned with booleans.

def logged_in?
  user
end

If the user is nil, then logged_in? will return a “falsey” value. Otherwise, it will return an object. In Ruby we don’t need to return true or false, since we have “truthy” and “falsey” values like in JavaScript.

Update

If you’re using Rails, you can make this read more nicely by using the present? method:

def logged_in?
  user.present?
end

Leave a Comment

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