forked from Ada-C6/BankAccounts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbank_account_wave1.rb
More file actions
55 lines (49 loc) · 1.25 KB
/
bank_account_wave1.rb
File metadata and controls
55 lines (49 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class Owner
attr_accessor :name, :address, :phone
def initialize(hash_parameter)
@name = hash_parameter[:name]
@address = hash_parameter[:address]
@phone = hash_parameter[:phone]
end
def to_s
return "Name: #{@name}, Address: #{@address}, Phone: #{@phone}"
end
end
customer1 = Owner.new(name: "joey", address: "5th ave", phone: 555345567)
module Bank
class Account
attr_accessor :customer_info, :id, :balance, :owner_info
def initialize(id, initial_deposit, owner_info)
@owner_info = owner_info
@id = id
if initial_deposit < 0
raise ArgumentError.new("You cannot have negative money.")
end
@balance = initial_deposit
end
def withdraw(take)
if take > @balance
puts "You do not have enough money to withdraw that amount."
else
@balance -= take
end
return @balance
end
def deposit(give)
if give <= 0
puts "Looks like you are actually trying to withdraw."
else
@balance += give
end
end
def balance
return @balance
end
end
end
account1 = Bank::Account.new(rand(100000..999999), 50, customer1)
account1.withdraw(60)
account1.deposit(40)
puts account1.balance
puts account1.id
puts account1.owner_info