def +(other)
result.b = self.b - other.b
end @d = b**2 - (4ac)
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.