Drew Skrainka Drew Skrainka - 6 months ago 9
Ruby Question

difference between .nil? and == nil

I'm working through the Ruby on Rails tutorial, and I'm curious about this codeblock:

if remember_digest.nil?
false
else
BCrypt::Password.new(remember_digest).is_password?(remember_token)
end


is there a difference between
if remember_digest.nil?
and
if remember_digest == nil
, or is this just the author's preference?

Answer

No difference. According to docs, only nil object responds true to nil?.

Comments