From: Learning Ruby Date: 2006-11-03T22:30:22+09:00 Subject: Re: Output not clear ------=_Part_21105_24514079.1162560617866 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 11/3/06, Rimantas Liubertas wrote: > > > def withdraw(amt) > > @bal = balance > > if ((@bal - amt) > 500.00) > > balance = @bal - amt > > puts balance.to_s > > else > > puts 'No Balance' > > end > > end > > end > > > > s = Savings.new('Pete',65241884,5000.00) > > s.deposit(500.00) > > s.withdraw(200.00) > > puts s.balance.to_s > > > > The output I get is: > > > > >ruby accounts.rb > > 5500.0 > > 5300.0 > > 5500.0 > > >Exit code: 0 > > > > I thought that the last line puts s.balance.to_s would have displayed > 5300.0. > > Why is this 5500.0 ? > > > Because you do not change @balance in your withdraw method. > > Regards, > Rimantas > More confusion. I thought that the statement balance = @bal - amt in the withdraw method is actually the set method for the @balance variable of the Accounts class. Is not the set method inherited in the Savings class? ------=_Part_21105_24514079.1162560617866--