I am trying to build up some classes using inheritance but I’m not
getting the expected results
Here are my classes and test data
class Control
attr :attributes, true
def initialize(x, y, w, h)
@attributes = {
‘x’=>x,
‘y’=>y,
‘h’=>w,
‘w’=>h
}
end
def getAttributes
return @attributes
end
end
class StaticTextControl < Control
def initialize(x, y, w, h, xBorder, yBorder, fontSize, fontMode,
phrase)
super(x, y, w, h)
@@desc = ‘STATIC_TEXT_CONTROL’
@attributes = {
‘xBorder’=>xBorder,
‘yBorder’=>yBorder,
‘fontSize’=>fontSize,
‘fontMode’=>fontMode,
‘phrase’=>phrase
}
end
def getAttributes
return @attributes.merge(super)
end
end
stc = StaticTextControl.new(1,2,3,4,5,6,7,8,9)
puts stc.getAttributes
When I run the script I get this:
returning attributes {“phrase”=>9, “xBorder”=>5, “fontSize”=>7,
“yBorder”=>6, “fontMode”=>8}
phrase9xBorder5yBorder6fontSize7fontMode8
I am expecting the attributes from the super class to be included as
well.
Can anyone tell me what I’m doing wrong?
Thanks.