[ create a new paste ] login | about

Link: http://codepad.org/7ODkvOpF    [ raw code | fork ]

Ruby, pasted on Sep 22:
class Account
  def initialize(balance)
    @balance = balance
  end

  def debit(amount)
    result = [amount,@balance].min
    @balance -= result
    result
  end

  def credit(amount)
    @balance += amount
  end
end

class Transaction
  def initialize(account_a, account_b)
    @account_a = account_a
    @account_b = account_b
  end

  def transfer(amount)
    @account_b.credit @account_a.debit amount
  end
end


Create a new paste based on this one


Comments: