35 lines
518 B
Ruby
Executable File
35 lines
518 B
Ruby
Executable File
#!/usr/bin/ruby
|
|
# -*- coding: utf-8 -*-
|
|
|
|
=begin
|
|
잔액 부족 예외 처리
|
|
=end
|
|
|
|
class BankAccount
|
|
def initialize(balance)
|
|
@balance = balance
|
|
end
|
|
|
|
def deposit(amount)
|
|
@balance += amount
|
|
end
|
|
|
|
def withdraw(amount)
|
|
begin
|
|
raise StandardError if @balance < amount
|
|
@balance -= amount
|
|
rescue
|
|
puts "잔액이 부족합니다."
|
|
@balance
|
|
end
|
|
|
|
end
|
|
|
|
def get_balance
|
|
@balance
|
|
end
|
|
end
|
|
|
|
account = BankAccount.new(100)
|
|
puts account.withdraw(99)
|
|
puts account.withdraw(5) |