-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathoop2.rb
More file actions
39 lines (33 loc) · 797 Bytes
/
oop2.rb
File metadata and controls
39 lines (33 loc) · 797 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
class Person
def initialize(name, age)
@name = name
@age = age
end
attr_reader :name, :age
attr_writer :name, :age
end
class Employee < Person
def initialize(name, age, empno)
super(name, age)
@empno = empno
end
attr_reader :empno
attr_writer :empno
def add(obj)
if obj.class == Employee
return Employee.new(@name + obj.name + "as a group", (@age + obj.age)/2, @empno + "," + obj.empno)
end
end
def +(obj)
self.add(obj)
end
end
begin
susan = Employee.new("Susan", 20, "10010")
print susan.name
print susan.age
print susan.empno
phillip = Employee.new("Phillip", 26, "5637")
group1 = susan + phillip
print group1.name, group1.age, group1.empno
end