-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path07-classes.rb
More file actions
54 lines (42 loc) · 912 Bytes
/
07-classes.rb
File metadata and controls
54 lines (42 loc) · 912 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
49
50
51
52
53
54
# objects and classes
# a module groups related classes
module GameDepot
class Game
attr_accessor :title
attr_accessor :price
attr_accessor :genre
def initialize(title,price,genre)
@title = title
@price = price
@genre = genre
end
def discount()
if Time.now.strftime("%A") == "Sunday"
0.8*price
else
price
end
end
end
class GameConsole
attr_reader :maker
attr_reader :name
def initialize(maker,name,price)
@maker = maker
@name = name
@price = price
end
def price
@price
end
def price=(new_price)
@price = new_price
end
end
end
tetris = GameDepot::Game.new("Tetris",100,"Puzzle")
puts tetris.discount
puts tetris.title
wii = GameDepot::GameConsole.new("Nintendo","Wii",300)
wii.price = 200
puts "New price for Wii is #{wii.price}"