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.
def initailize(y, x, height, width, linecolor, fillcolor, linewidth)
@y = y
@x = x
@height = height
@width = width
@linecolor = linecolor
@fillcolor = fillcolor
@linewidth = linewidth
attr_accessor :y, :x, :height, :width, :linecolor, :fillcolor,
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