![]() |
calling setter method from initialize method
Hi all,
Why doesn't aAttribute get set? class AClass attr_accessor :aAttribute, :bAttribute def initialize() aAttribute= 1 @bAttribute= 1 end end a= AClass.new a.aAttribute # nil a.bAttribute # 1 |
Re: calling setter method from initialize method
Sorry for the noise. I was in a a weird head space :), it should be
self.aAttribute. On Aug 14, 12:46*am, Le Wang <lewang1980use...@gmail.com> wrote: > Hi all, > > Why doesn't aAttribute get set? > > class AClass > * attr_accessor :aAttribute, :bAttribute > * def initialize() > * * aAttribute= 1 > * * @bAttribute= 1 > * end > end > > a= AClass.new > a.aAttribute * * * * * * * * * # nil > a.bAttribute * * * * * * * * * # 1 |
Re: calling setter method from initialize method
Am 13.08.2011 18:46, schrieb Le Wang:
> class AClass > attr_accessor :aAttribute, :bAttribute > def initialize() > aAttribute= 1 > @bAttribute= 1 > end > end > > a= AClass.new > a.aAttribute # nil > a.bAttribute # 1 With aAttribute= 1 you define a local variable aAttribute. You have to use self.aAttribute= 1 |
| All times are GMT. The time now is 07:09 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.