Is there a performance gain in comparing objects like this…
current_user.id == @user.id
versus this …
current_user == @user
Also are there best-practice reasons for doing one over the other regardless of performance?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, but barely.
ActiveRecord::Base#==does this:Which essentially compares
ids but ensures that the objects are of the same type, which you probably want since, for example, if you compared justids they could be the same even though one is aUserand another aProduct.In conclusion, comparing the model objects themselves is best.