-
Notifications
You must be signed in to change notification settings - Fork 0
/
part4_oop.rb
70 lines (57 loc) · 954 Bytes
/
part4_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
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
class Dessert
def initialize(name, calories)
@name, @calories = name, calories
end
def name
@name
end
def name=(name)
@name = name
end
def calories
@calories
end
def calories=(calories)
@calories = calories
end
def healthy?
@calories.to_i < 200
end
def delicious?
true
end
end
class JellyBean < Dessert
def initialize(name, calories, flavor)
super(name, calories)
@flavor = flavor
end
def flavor
@flavor
end
def flavor=(flavor)
@flavor = flavor
end
def delicious?
@flavor != "black licorice"
end
end
# a = Dessert.new("cake", 101)
# puts a.to_s
# puts a.healthy?
# puts a.delicious?
# puts a.name()
# a.name = 'cake3'
# puts a.name
# a.calories = 200
# puts a.calories()
# puts a.healthy?
# b = JellyBean.new('cake2', 100, 'sweet')
# puts b.to_s
# puts b.name()
# puts b.healthy?
# puts b.delicious?
# puts b.flavor()
# b.flavor = 'black licorice'
# puts b.flavor()
# puts b.delicious?