Possible Duplicate:
Difference between “and” and && in Ruby?
I realized there are differences between and
and &&
in Ruby (this was one confusing sentence).
@show_votes = !current_user.nil? and current_user.is_admin?
if @show_votes
#code assumes everyone logged in is admin
end
Whereas:
@show_votes = !current_user.nil? && current_user.is_admin?
if @show_votes
#code assumes only admin is admin
end
What is the difference between the two operators? I found that they have different operating precedence, but still can not figure out what the real difference is.
(the application was written with Rails. Although I would expect the same to occur in Sinatra as this is most likely something to do with the Ruby language)
edited the code to better reflect the situation.