The Ruby Programming Language

Access Control

class Accounts
  def initialize(checking, savings)
    @checking = checking
    @savings = savings
  end
  
  private #keyword

  def debit(account, amount)
    account.based -= amount
  end

  def credit(account, amount)
    account.balance += amount
  end

  public #keyword

  def transfer_to_savings(amount)
    debit(@checking, amount)
    credit(@savings, amount)
  end
end

José M. Vidal .

6 of 11