Within a Model , when I have a variable write operation in a method, why do I need to add self to work correctly?
For example, if I have the following code:
class Zombie < ActiveRecord::Base
beffore_save :make_rotting
def make_rotting
if age > 20
self.rotting = true
end
end
end
On the other hand, if I omit the self, it does not work:
class Zombie < ActiveRecord::Base
beffore_save :make_rotting
def make_rotting
if age > 20
rotting = true #No funciona correctamente
end
end
end
Note : variable age reads it without any problem in both cases.
Why is there a difference in the behavior of rotting with the presence of self , while in age does not change?