From: "Jesús Gabriel y Galán" Date: 2012-02-10T00:58:21+09:00 Subject: Re: why doesn't work On Thu, Feb 9, 2012 at 4:17 PM, luk malcik wrote: > why method pierw doesn't run? > > > class Wielomian >   attr_accessor :a, :b, :c > >  def initialize >   @d >  end > >  def +(other) >   result = Wielomian.new >   result.a = self.a + other.a >   result.b = self.b + other.b >   result.c = self.c + other.c >   result >  end > >  def -(other) >   result = Wielomian.new >   result.a = self.a - other.a >   result.b = self.b - other.b >   result.c = self.c - other.c >   result >  end > > def *(other) >   result = Wielomian.new >   result.a = self.a * other.a >   result.b = self.b * other.b >   result.c = self.c * other.c >   result >  end > > def /(other) >   result = Wielomian.new >   result.a = self.a / other.a >   result.b = self.b / other.b >   result.c = self.c / other.c >   result >  end > >  def delta >   @d = b**2 - (4*a*c) >  end > > def pierw >  x1 = -(b - (Math.sqrt(@d))/2*a) >  end > > end There are several strange things here. First of all, in initialize, @d evaluates to nil and doesn't setup anything at all. You define attr_accessor for a, b and c, so I guess the client code does: w = Wielomian.new w.a = 3 w.b = 4 w.c = 5 If you then call w.pierw, @d is still nil. You might be better off (but we need more information) to assign a, b and c in the initialize method, which right away could calculate the value for @d, setting your object in a complete state: class Wielomian def initialize a,b,c @a = a @b = b @c = c delta end # ... the rest end w = Wieloman(3,4,5) w.pierw Also, in the pierw method, assigning to a local variable x1 that is not used is useless. You can drop the assignment. Hope this helps, Jesus.