-
Notifications
You must be signed in to change notification settings - Fork 0
/
kodomocurry.rb
79 lines (66 loc) · 1.44 KB
/
kodomocurry.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
71
72
73
74
75
76
77
78
class Curry
def initialize(a=3,b=300) #初期値は辛さ3量は300
@karasa=a
@ryou=b
end
def setkarasa(a)
@karasa=a
end
def setryou(b)
if b<0
@ryou=300
puts "WARN:量として負の値は設定できません 勝手に初期値にします"
else
@ryou=b
end
end
def getkarasa
return(@karasa)
end
def getryou
return(@ryou)
end
end
class KodomoCurry < Curry #KodomoCurry extends Curry(継承)
@@c=true
def initialize(a=1,b=200) #新たにコンストラクタ
@karasa=a
@ryou=b
@c=true
end
def openOmake #おまけメソッド
if(@c==true)
puts "Omake OPEN!"
else
puts "もうおまけないよ"
end
@c=false
end
def setkarasa(a) #5を中辛とする
if a>=5
@karasa=4 #強制甘口変更
else
@karasa=a
end
end
end
dora=Curry.new(5)
nobi=KodomoCurry.new
unk=KodomoCurry.new
dora.setkarasa(9999)
puts "dora"
puts "karasa=#{dora.getkarasa}"
puts "ryou=#{dora.getryou}"
nobi.setkarasa(99999)
puts "nobi"
puts "karasa=#{nobi.getkarasa}"
puts "ryou=#{nobi.getryou}"
nobi.openOmake
nobi.openOmake
unk.openOmake
sizuka=KodomoCurry.new()
sizuka.setkarasa(3)
sizuka.setryou(-100)
puts "sizuka"
puts "karasa=#{sizuka.getkarasa}"
puts "ryou=#{sizuka.getryou}"