-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBankAccount.rb
72 lines (59 loc) · 1.41 KB
/
BankAccount.rb
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
class BankAccount
attr_accessor :balance
def initialize( owner )
@owner = owner
@balance = 0
end
def deposite( amount )
@balance += amount
end
def withdraw( amount )
@balance -= amount
end
def who_am_i
puts "hello im #{self} and my name is #{@owner}"
end
#def balance #Depricated since attr_accessor
# @balance
#end
#def balance= ( amount ) #Depricated since attr_accessor
# @balance = amount
#end
end
class InterestBearingAccount < BankAccount
def initialize (owner, rate)
super owner
@rate = rate
end
def deposite_interest
@balance += @rate * @balance
end
def deposite(amount, add = 0)
super amount
super add if add > 0
end
def add_big_sum(*amounts)
summ = 0
prev_n = 0
amounts.each do |n|
summ += n * prev_n if prev_n != 0
prev_n = n
end
@balance += summ
end
end
russHolder = BankAccount.new "Scheglakov"
russHolder.deposite 200
russHolder.withdraw 300
russHolder.deposite 500
russHolder.balance = 1337
newRuss = InterestBearingAccount.new "Alexander", 2
newRuss.deposite 100
newRuss.deposite_interest
newRuss.deposite 100
newRuss.deposite 100, 100
newRuss.add_big_sum 2,3,4,5,100,200
puts russHolder.balance
puts "Eazy Life with Ruby"
puts russHolder.who_am_i
puts "And newRuss-#{newRuss.who_am_i} balance is: #{newRuss.balance}"