In this book:
http://ruby.railstutorial.org/chapters/updating-showing-and-deleting-users#code:current_user_p
The author does the following:
def current_user
@current_user ||= User.find_by_remember_token(cookies[:remember_token])
end
def current_user?(user)
user == current_user
end
my question is when there is a comparison, user == current_user; what is rails comparing? user == @current_user? or user.name == @current_user.name ?
What would hapen if I had the following
def current_user
@current_user ||= User.find_by_remember_token(cookies[:remember_token])
@other_user ||= User.find_by_other_token(cookies[:other_token])
end
would ser == current_user compare other_user?
The
current_userinuser == current_useris a call to thecurrent_usermethod, and in ruby a method returns the last statement that is executed. So in the example,@current_useris being compared touser.If you add
@other_userto thecurrent_usermethod, then you are correct in thinking thatuser == current_userwould compare user to@other_user.