From: Jason Roelofs Date: 2010-06-16T20:28:15+09:00 Subject: Re: Getting rid of self --000e0cd564505ff00c0489240487 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 2010/6/16 Jes=FAs Gabriel y Gal=E1n > On Wed, Jun 16, 2010 at 11:37 AM, Andrea Dallera > wrote: > > Have you tried it like this? > > > > > > --- > > > > def initialize(attributes =3D nil) > > > > super attributes > > > > step =3D 0 > > > > national_debt =3D 0 > > > > sum_of_income =3D 0 > > > > sum_of_taxes =3D 0 > > > > sum_of_happiness =3D 0 > > > > sum_of_investments =3D 0 > > > > end > > > > --- > > > > > > 'self' is the default receiver inside a method > > That won't work, because the parser sees this as local variable > assignments, and not method calls. > I don't know an easy way to remove that. > If they're ivars (attr_accessible), then just use the ivar itself. If they are methods on the class, then you'll need the self for there reason you mentioned: def initialize(attributes =3D nil) super # If exact signature, don't need arguments @step =3D 0 @national_debt =3D 0 @sum_of_income =3D 0 @sum_of_taxes =3D 0 @sum_of_happiness =3D 0 @sum_of_investments =3D 0 end Oh, and you never need to return anything from #initialize. Jason --000e0cd564505ff00c0489240487--