-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathzoo.rb
More file actions
71 lines (52 loc) · 671 Bytes
/
zoo.rb
File metadata and controls
71 lines (52 loc) · 671 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
67
68
69
70
#Zoo
module Animal
def eat(food)
@meals ||= 0
if likes?(food)
@meals += 1
true
else
false
end
end
def likes?(food)
acceptable_food.include?(food.to_sym)
end
def acceptable_food
[]
end
def full?
false
end
end
class Panda
include Animal
def acceptable_food
[:bamboo]
end
def full?
@meals > 30
end
end
class Lion
include Animal
def acceptable_food
[:wildebeests, :zeebras]
end
def full?
@meals > 10
end
end
class Zookeeper
def feed(args={})
food = args.fetch(:food)
panda = args.fetch(:to)
panda.eat(food)
end
end
class Human
include Animal
def acceptable_food
[:bacon, :tacos]
end
end