From: Davy Brion Date: 2010-09-10T23:47:42+09:00 Subject: Re: calling private accessors --001636c5ab911273cb048fe8d4fc Content-Type: text/plain; charset=UTF-8 On Fri, Sep 10, 2010 at 4:18 PM, Brian Candler wrote: > Davy Brion wrote: > > def set_the_name(value) > > name = value > > end > > To Ruby, that's an assignment to a local variable, which then drops out > of scope. That's why you have to do "self.name= value" to call the > method. > d'oh! of course :) > If it really were private, you'd need > > send(:name=, value) > > although being private rather negates the purpose of an 'accessor' which > is to make values accessible :-) > > in this case, i only want the accessor to be acessible to the class and its subclasses, mainly because the subclasses need to be able to override the 'storage mechanism' (ie: backing field vs hash or something)... it's a bid of an edge-case though :) > > when calling the private accessor without using self, its > > implementation > > clearly isn't executed but no exception is raised either... why is that? > > Because it's perfectly legal to assign a value to a local variable :-) > obviously :P --001636c5ab911273cb048fe8d4fc--