From: Saji Hameed Date: 2012-04-10T15:30:06+09:00 Subject: Re: New to Ruby, tutorial gives wrong example. --f46d040710abb658cf04bd4d4096 Content-Type: text/plain; charset=UTF-8 You maxe a spelling mistake in the method name initialize. "def initailize " -> def initialize saji On Tue, Apr 10, 2012 at 3:18 PM, Roger McDonald wrote: > I am just starting with Ruby with intention to learn and perhaps use it > to produce a GUI slightly different to RoR. > > It's interesting to note how many times one has to enter the same text. > > Take this example, from troubleshooters.com #How OOP is Ruby. > Incidentally it does not work.- very frustrating for a beginner. > > #!/usr/bin/ruby > > class Rectangle > def initailize(y, x, height, width, linecolor, fillcolor, linewidth) > @y = y > @x = x > @height = height > @width = width > @linecolor = linecolor > @fillcolor = fillcolor > @linewidth = linewidth > end > attr_accessor :y, :x, :height, :width, :linecolor, :fillcolor, > :linewidth > end > > rect = Rectangle.new(10, 20, 50, 60, "blue","yellow") > rect.linewidth = 4 > puts rect.x.to_s+", "+rect.fillcolor + ", "+rect.linewidth.to_s > -------============------------- > > Just this required the same text 3 times, one to initialise, one to > declare variables and one for attr_accessor > > Its just a simple tutorial app which produces error on line 16 wrong > number of arguments (6 for 0) ArgumentError. Not a helpful error and > Google is of little help. > > I tried adding another value to the rect=Rectangle.new list above but > that does not work either. > > It seems such a waste to type the same thing over and over, is there any > reason that a set of variables cannot be initialised, declared, > populated and attributed as above, in the same line? reducing typos. > > Help in understanding is greatly appreciated > thank you in advance > Roger > > -- > Posted via http://www.ruby-forum.com/. > > -- 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 --f46d040710abb658cf04bd4d4096 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable You maxe a spelling mistake in the method name initialize.
"def ini= tailize " -> def initialize

saji

On Tue, Apr 10, 2012 at 3:18 PM, Roger McDonald &l= t;lists@ruby-forum.com> wrote:
I am just starting with Ruby with intention = to learn and perhaps use it
to produce a GUI slightly different to RoR.

It's interesting to note how many times one has to enter the same text.=

Take this example, from troubleshooters.com #How OOP is Ruby.
Incidentally it does not work.- very frustrating for a beginner.

#!/usr/bin/ruby

class Rectangle
=C2=A0def initailize(y, x, height, width, linecolor, fillcolor, linewidth)=
=C2=A0 =C2=A0@y =3D y
=C2=A0 =C2=A0@x =3D x
=C2=A0 =C2=A0@height =3D height
=C2=A0 =C2=A0@width =3D width
=C2=A0 =C2=A0@linecolor =3D linecolor
=C2=A0 =C2=A0@fillcolor =3D fillcolor
=C2=A0 =C2=A0@linewidth =3D linewidth
=C2=A0end
=C2=A0attr_accessor :y, :x, :height, :width, :linecolor, :fillcolor,
:linewidth
end

rect =3D Rectangle.new(10, 20, 50, 60, "blue","yellow")=
rect.linewidth =3D 4
puts rect.x.to_s+", "+rect.fillcolor + ", "+rect.linewi= dth.to_s
-------=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D-------------

Just this required the same text 3 times, one to initialise, one to
declare variables and one for attr_accessor

Its just a simple tutorial app which produces error on line 16 wrong
number of arguments (6 for 0) ArgumentError. Not a helpful error and
Google is of little help.

I tried adding another value to the rect=3DRectangle.new list above but
that does not work either.

It seems such a waste to type the same thing over and over, is there any reason that a set of variables cannot be initialised, declared,
populated and attributed as above, in the same line? reducing typos.

Help in understanding is greatly appreciated
thank you in advance
Roger

--
Posted via http://= www.ruby-forum.com/.




--

Saji = N Hameed,
ARC-ENV, Center for Advanced Information Science and Technolog= y,
University of Aizu, Tsuruga, Ikki-machi,
Aizuwakamatsu-shi, Fukush= ima 965-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
--f46d040710abb658cf04bd4d4096--