Fred wrote: > Hello, > > I just finished reading the Agile book. Of course I forgot at least the > two thirds of what I read. I started reading the source code of Typo, to > see a real (and Rails) application. > > I stumbled upon this snippet of code: > > def crypt_unless_empty > if password(true).empty? > user = self.class.find(self.id) > self.password = user.password > else > write_attribute "password", self.class.sha1(password(true)) > @password = nil > end > end > > is there any practical reason to use sometimes self.password and > sometimes @password? I thought they were synonyms... The difference between `self.attr = val' and `@attr = val' is simply that the first is a method call, i.e. the same as `self.attr=(val)'. The `attr=' method may check the value, and do a lot of different things - when you use `@attr = val', the only thing happening is that you assign the instance variable `attr' the value of `val'. Take this, for instance: class User attr_reader :name def initialize(name) # @name will be a string self.name = name end def name=(val) # make sure @name is a string @name = val.to_str end end Cheers, Daniel