Inheritance one more time

Hi, similar topic was here but still I can't do that. This is my code:

Square = Struct.new(:x,:y,:a) do

   include Domieszka

   def pole

   p = a**2

   end

   def obwod

   o = 4*a

   end

   def pole=(a)

   self.a = a

   end

   def obwod=(a)

   self.a = a

   end

end

class Rectangle<Square

   include Domieszka

   def pole=(b)

   self.b = b
   end
   def pole
   p=a*b

   end

Why there is no possibility to write :
r = Rectangle.new
r.pole = 3
"Undefinied method error..."

Domieszka is module declared at the beginning of my code, I dont put it
here

···

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

I'm not sure what's in your Domieszka module, but in the code you
pasted, there are no methods b or b= in Rectangle; and there are no
methods a or a= in Square. The missing Rectangle#b= is why r.pole = 3
doesn't work.

Also, since you include Domieszka in the superclass, there's no need
to include it again in the subclass.

···

On Sun, Feb 5, 2012 at 4:48 PM, luk malcik <aport99@gmail.com> wrote:

Hi, similar topic was here but still I can't do that. This is my code:

Square = Struct.new(:x,:y,:a) do

include Domieszka

def pole

p = a**2

end

def obwod

o = 4*a

end

def pole=(a)

self.a = a

end

def obwod=(a)

self.a = a

end

end

class Rectangle<Square

include Domieszka

def pole=(b)

self.b = b
end
def pole
p=a*b

end

Why there is no possibility to write :
r = Rectangle.new
r.pole = 3
"Undefinied method error..."

Domieszka is module declared at the beginning of my code, I dont put it
here

That's full of code. I think there is no problem with Domieszka.

module Domieszka

attr_accessor :x, :y

   def moveto(x,y)

         @x = x

         @y = y

         end

end

Circle = Struct.new(:x,:y,:r) do

   include Domieszka

   def field

   p = Math::PI * r**2

   end

   def field=(r)

   self.r = r

   end

   def obwod

   o = 2*Math::PI*r

   end

   def obwod=(r)

   self.r = r

   end

end

Square = Struct.new(:x,:y,:a) do

   include Domieszka

   def field

   p = a**2

   end

   def obwod

   o = 4*a

   end

   def field=(a)

   self.a = a

   end

   def obwod=(a)

   self.a = a

   end

end

class Rectangle<Square

   def fieldRect=(b)

   self.b = b
   end
   def fieldRect
   p=a*b

   end
end

···

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

Oh, right -- I forgot Square is a struct with a and a= defined on it.
Since you have
  self.b = b
you need to define b=, e.g. by defining an accessor:
  attr_accessor :b

···

On Sun, Feb 5, 2012 at 7:21 PM, luk malcik <aport99@gmail.com> wrote:

Square = Struct.new(:x,:y,:a) do