From: takaoueda@... Date: 2000-12-19T00:40:02+09:00 Subject: [ruby-talk:7582] New to Ruby I have just started learning Ruby with the book of Thomas and Hunt. The book is readable, but sample code is often an incomplete program. So I am filling the gaps for exercises. I concocted the following program for pp 31-32 by trial and error. Will someone give a better solution to this cross-word puzzle? I had to change the local variables checking and savings to instance variables @checking and @savings. class Account attr_reader :balance attr_accessor :balance def initialize(name, balance) @balance = balance @name = name end end class Accounts def initialize @checking = Account.new("checking", 2000) @savings = Account.new("saving", 1000) end private def debit(account, amount) account.balance -= amount end def credit(account, amount) account.balance += amount end public def transferToSavings(amount) print "Checking balance: ", debit(@checking, amount), " " print "Savings balance: ", credit(@savings, amount), "\n" end end accs = Accounts.new accs.transferToSavings(300) accs.transferToSavings(-200) Sent via Deja.com http://www.deja.com/