Skip to content

Instantly share code, notes, and snippets.

@sirramongabriel
Last active December 22, 2015 04:28
Show Gist options
  • Save sirramongabriel/6416816 to your computer and use it in GitHub Desktop.
Save sirramongabriel/6416816 to your computer and use it in GitHub Desktop.
From project banking. The account class
# account.rb
class Account
def initialize
@balance = 1000.00
end
attr_accessor :amount
def send_deposit
"#{deposit(amount, current_balance).to_f}"
end
def send_withdraw
"#{withdraw(amount, current_balance).to_f}"
end
def send_balance
"#{current_balance(deposit_amount, withdraw_amount).to_f}"
end
private
def deposit(amount, current_balance)
amount = gets.chomp
deposit_amount = amount.to_f
puts "You have deposited $#{deposit_amount} into your account."
puts "Your current_balance is now #{current_balance}."
end
def withdraw(amount, current_balance)
amount = gets.chomp
withdraw_amount = amount.to_f
puts "You have withdrawn $#{withdraw_amount} from your account."
puts "Your current_balance is now #{current_balance}."
end
def current_balance(deposit_amount, withdraw_amount)
unless deposit.blank?
@balance += deposit_amount
@balance
end
unless withdraw.blank?
@balance -= withdraw_amount
@balance
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment