I have a User object that extends ActiveRecord::Base.
And I have the following defined in it:
self.secure_password = User.encrypt(password)
And this works. Where I am getting confused about is the difference
between the following:
Because these versions of crypt_password method don’t work:
secure_password = User.encrypt(password)
@secure_password = User.encrypt(password)
When I debug the app by placing a breakpoint right after the assigment
in crypt_password, and ask for values:
@secure_password returns ‘nil’
secure_password returns the encrypted password…
Which is very puzzling.
First of all, I thought @ was used for instance variables. So
@secure_password should be the one with the encrypted value assigned not
Let’s forget that…If secure_password contains the encrypted value as I
see on the console, why would secure_password = User.encrypt(password)
call not do what I expect it to do?
Obviously, I’m pretty confused about the usage of @ vs. non-@, self,