Ruby Examples

This commit is contained in:
2026-01-15 14:01:21 +09:00
commit cf3d7d3296
76 changed files with 1191 additions and 0 deletions

35
level7/70.rb Executable file
View File

@@ -0,0 +1,35 @@
#!/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)