According to this stack question,
and
is the same as&&
but with lower precedence
And I understand this well. And I believe this question is not duplicate to the above question.
In my controller when executing the following code:
user = user_email.present? && User.find_by(email: user_email)
user
variable holds the active record object
for User
model. And thus executing user.valid_password? user_password
gave no error and test passed successfully.
But when I tried to replace &&
with and
the result is quite surprising.
When I tried with following code:
user = user_email.present? and User.find_by(email: user_email)
user
variable holds the boolean
value and thus executing user.valid_password? user_password
gave following error:
undefined method `valid_password?' for true:TrueClass
Can anyone please explain why this is happening.