-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinheritance.rb
More file actions
48 lines (38 loc) · 782 Bytes
/
inheritance.rb
File metadata and controls
48 lines (38 loc) · 782 Bytes
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
class Employee
attr_accessor :manager, :salary
def initialize(salary, title)
@salary = salary
@title = title
@manager = nil
end
def salary=(value)
@salary = value
end
def bonus(mulitiplier)
@salary * mulitiplier
end
end
class Manager < Employee
attr_accessor :employees
def initialize(salary, title)
super
@employees = []
end
def add_employees(*employee)
employee.each do |emp|
emp.manager = self
@employees << emp
end
end
def sub_salaries
total_salaries = 0
self.employees.each do |emp|
total_salaries += emp.salary
total_salaries += emp.sub_salaries if emp.class == Manager
end
total_salaries
end
def bonus(multiplier)
self.sub_salaries * multiplier
end
end