-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5-3.rb
More file actions
66 lines (49 loc) · 964 Bytes
/
5-3.rb
File metadata and controls
66 lines (49 loc) · 964 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
55
56
57
58
59
60
61
62
63
64
65
66
class Bone
attr_accessor :size
def initialize(size)
@size = size
end
end
class Dog
attr_accessor :color, :type, :bones
def initialize(color, type)
@color = color
@type = type
@bones = []
end
def give(abone)
if (abone.is_a? Bone) == true && bones.length < 3
bones << abone
elsif bones.length < 3
"I only want bones!!"
else
"too many bones"
end
end
def eat
if bones.length != 0
" Yummy, I ate a #{bones.pop.size} bone!!"
else
"I got no bones!!"
end
end
end
bone1 = Bone.new("colorful")
p bone1.size
bone2 = Bone.new("small")
bone3 = Bone.new("big")
p bone2.size
bone4 = Bone.new("fossil")
mike = Dog.new("bulldog", "green")
p mike.give(bone1)
mike.bones.each {|x| p x.size}
mike.give(bone2)
mike.bones.each {|x| p x.size}
mike.give(bone3)
mike.bones.each {|x| p x.size}
p mike.give(bone4)
mike.bones.each {|x| p x.size}
p mike.eat
p mike.eat
p mike.eat
p mike.eat