We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 674f661 commit 5923417Copy full SHA for 5923417
dog.rb
@@ -0,0 +1,30 @@
1
+class Dog
2
+
3
+ def initialize(color, type)
4
+ @color, @type = color, type
5
+ @bones = []
6
+ end
7
8
+ def give(bone)
9
+ # ensuring that the dog has less than three bones in order to accept a new
10
+ # one
11
+ if @bones.length < 3
12
+ # add the bone to the bones array
13
+ @bones << bone
14
+ else
15
+ puts "Too many bones!"
16
17
18
19
+ def eat
20
+ if @bones.length == 0
21
+ puts "There are no bones!"
22
23
+ # the pop method on the array will remove and return the last element
24
+ # in the array. In this case @bones.pop will give us back a "bone" object
25
+ # the "bone" object has a "size" attribute.
26
+ puts "I ate a #{@bones.pop.size} bone!"
27
28
29
30
+end
0 commit comments