From: Saji Hameed Date: 2012-05-25T11:49:17+09:00 Subject: Re: Modify an attribute in a method? --e0cb4efe323ce7d2ce04c0d369f7 Content-Type: text/plain; charset=UTF-8 On Fri, May 25, 2012 at 8:38 AM, Robinson Risquez wrote: > >> Hi all, I write the following problem to see if you can clarify me: >> How I can modify an attribute of an object in a method?, Eg: >> >> ----------- CLIPPED ---------- >> >> I explain: I want the attribute @attribute (which I pass as a parameter >> to the method adder) will be modified in the method adder (adding 1) >> constantly, printing its output in the while cycle. >> > Hope this helps ..... class SomeClass attr_accessor :attribute def initialize(attribute) @attribute = attribute end end val = SomeClass.new(5) k=0 while (k<10) do puts val.attribute+=1 k+=1 end cheers, saji -- Saji N Hameed, ARC-ENV, Center for Advanced Information Science and Technology, University of Aizu, Tsuruga, Ikki-machi, Aizuwakamatsu-shi, Fukushima 965-8580, Japan Tel: +81242 37-2736 Fax:+81242 37-2760 email: saji@u-aizu.ac.jp url: http://www.u-aizu.ac.jp bib: http://www.researcherid.com/rid/B-9188-2009 --e0cb4efe323ce7d2ce04c0d369f7 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


On Fri, May 25, 2012 at 8:38 AM, Robinson Risquez <lists@ruby-forum.com> wrote:
Hi all, I write the following problem to see if you can clarify me:
How I can modify an attribute of an object in a method?, Eg:

-----------=C2=A0 CLIPPED ----------

I explain: I want the attribute @attribute (which I pass as a parameter
to the method adder) will be modified in the method adder (adding 1)
constantly, printing its output in the while cycle.
<= /blockquote>

Hope this helps=C2=A0 .....

=C2=A0class SomeCla= ss
=C2=A0 attr_accessor :attribute

=C2=A0 def initialize(attribut= e)
=C2=A0=C2=A0=C2=A0 @attribute =3D attribute
=C2=A0 end
end

val =3D SomeClass.new(5)

k=3D0
while (k&= lt;10) do
=C2=A0 puts val.attribute+=3D1
=C2=A0 k+=3D1
end

= cheers,
saji
--

Saji N Hameed,
ARC-ENV, Center= for Advanced Information Science and Technology,
University of Aizu, Tsuruga, Ikki-machi,
Aizuwakamatsu-shi, Fukushima 96= 5-8580,
Japan
=C2=A0 =C2=A0 =C2=A0 =C2=A0
Tel: +81242 37-2736
= Fax:+81242 37-2760
=C2=A0email: saji@u-aizu.ac.jp
=C2=A0url: http://www= .u-aizu.ac.jp
=C2=A0bib: http://www.researcherid.com/rid/B-9188-2009<= /a>
--e0cb4efe323ce7d2ce04c0d369f7--