Ey guys, how are you? I’m wondering if you can give me your advice.
First the problem:
.
.
attr_accessor :attribute1 :attribute2 :attribute3
.
.
@attribute1 = 3
@attribute2 = 5
@attribute3 = 1
@total = 9
#this last attribute must be the result of the summation of @attribute1
- #@attribute2 + @attribute3.
.
.
So what’s the best way to reflect the explained in the comments inside
the code. Will be very nice if i can assign the value of attribute1, 2
or 3 with the attr_accessor facility. How can the value of @total be
refreshed when one of attribute1, 2 or 3 has his value changed? I though
in do(instead of the attr_accessor facility) one writer method for each
of the 3 attribute, like this:
def change_attribute1(new_value)
@total = @attribute2 + @attribute3 + new_value
@attribute1 = new_value
end
#and so on with the others attributes
but this seems sicken. Is there any way to link the values of the
attributes with @total with the attr_accessor facility or other way…or
I’m just limited to the last option. Thank’s for your time. Damián.