-
Notifications
You must be signed in to change notification settings - Fork 3
/
oop.rb
46 lines (38 loc) · 777 Bytes
/
oop.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
class Newclass
def initialize(total)
@total = total
end
def add(value)
@total += value
end
def set(value)
@total = value
end
def get
return @total
end
def hastotal
return @total != nil
end
def otherval
return @otherval
end
def otherval=(arg)
@otherval=arg
end
attr_reader :anotherval, :anothervaltoo
attr_writer :anotherval, :anothervaltoo
end
begin
class1 = Newclass.new(0)
#print class1.class
class1.set(17)
class1.add(7)
print class1.get
print class1.hastotal
class1.otherval = 17
print class1.otherval
class1.anotherval = 25
class1.anothervaltoo = 24
print class1.anotherval, class1.anothervaltoo
end