-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path11-subclass.rb
More file actions
45 lines (37 loc) · 1.07 KB
/
11-subclass.rb
File metadata and controls
45 lines (37 loc) · 1.07 KB
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
# subclass
require_relative '07-classes.rb'
module GameDepot
# constant
CORPORATE_SLOGAN = "You can play it. We can help."
class UsedGame < Game
# class variable
@@slogan = "All used games come with limited warranties"
attr_accessor :condition
def initialize(title,price,genre,condition)
super(title,price,genre)
@condition = condition
adjust_price_condition
end
def adjust_price_condition
return if @price <= 10
if @condition == "Very Good"
@price -= 5
elsif @condition == "Good"
@price -= 10
elsif @condition == "Acceptable"
@price -= 15
end
end
# class method, self keyword can be replaced with the class name
def self.warranty(condition)
return "One Month" if condition == "Like New"
return "Two Month" if condition == "Very Good"
return "Three Month" if condition == "Good"
return "Four Month" if condition == "Acceptable"
end
# reader for class variable
def self.get_slogan
@@slogan
end
end
end