new2cpp new2cpp - 4 months ago 7
Ruby Question

What's the purpose of question mark in the beginning of variable?

https://www.railstutorial.org/book/advanced_login#code-login_create_user_instance has some example code

def create
?user = User.find_by(email: params[:session][:email].downcase)
if ?user && ?user.authenticate(params[:session][:password])
log_in ?user
params[:session][:remember_me] == '1' ? remember(?user) : forget(?user)
redirect_to ?user
else
flash.now[:danger] = 'Invalid email/password combination'
render 'new'
end
end


However, I still cannot understand the purpose of
?user
here. It is not a typo, right?

Answer

Just before this example there is an intro to it:

By filling in the missing elements in Listing 9.27 and Listing 9.28 (indicated with question marks ? and FILL_IN), complete this improved test of the “remember me” checkbox.

It always makes sense to read tutorials, not to scan them with a broken eye.