From: Davy Brion Date: 2010-09-10T23:02:18+09:00 Subject: calling private accessors --0015175ce1ecaa39d5048fe83143 Content-Type: text/plain; charset=UTF-8 Hi, i bumbed into something weird today, and would like to know what's going on... here's a contrived example: class Test attr_reader :name def set_the_name(value) name = value end private def name=(value) @name = value end end test = Test.new test.set_the_name "some name" p test the output of this on ruby 1.8.7 (as wel as on 1.9.2) is: # the name accessor wasn't called, but there was no error either if i change the set_the_name method to this: def set_the_name(value) self.name = value end then the output changes to this: # there are two things i don't quite understand about this: 1) i thought private methods should never be called through self, and that they are implicitely called on self. calling a non-accessor private method on self does raise the expected error. why does the accessor need to be called using self? 2) when calling the private accessor without using self, its implementation clearly isn't executed but no exception is raised either... why is that? --0015175ce1ecaa39d5048fe83143--