Created
April 28, 2013 09:18
-
-
Save ukutaht/5476380 to your computer and use it in GitHub Desktop.
Small logic snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bank Teller Project | |
def add_account(name, password, accounts) | |
accounts = {'name'=>name,'password'=>password,'balance'=>0} | |
return accounts | |
end | |
def get_balance(accounts) | |
return accounts['balance'] | |
end | |
def do_deposit(accounts, amount) | |
accounts['balance'] += amount.to_i | |
return accounts | |
end | |
def do_withdraw(accounts, amount) | |
if accounts['balance'] >= amount | |
accounts['balance'] -= amount | |
end | |
return accounts | |
end | |
def do_transfer(debtor, creditor, amount) | |
accounts = {} | |
if debtor['balance'] >= amount | |
creditor['balance'] = creditor['balance'] + amount | |
debtor['balance'] = debtor['balance'] - amount | |
end | |
accounts['debtor'] = debtor | |
accounts['creditor'] = creditor | |
return accounts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment