-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnoisy_animal.rb
60 lines (53 loc) · 1.08 KB
/
noisy_animal.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
# frozen_string_literal: true
class NoisyAnimal
attr_reader :species
def initialize(species)
@species = species
end
def make_noise(loud: true)
if is_bird && !loud
make_bird_noise(false)
end
if loud
if mammal_noise
2.times { puts mammal_noise }
end
make_bird_noise(true) if is_bird
elsif %w[cat dog leopard].include?(species)
puts mammal_noise
end
end
private
def mammal_noise
{
'cat' => 'meow',
'dog' => 'woof',
'leopard' => 'growl'
}[species]
end
def make_bird_noise(is_loud = true)
if species == 'hadedah'
puts 'squawk'
elsif species == 'eagle'
puts 'caw'
else
puts 'hoot'
end
if is_loud
if species == 'owl'
puts 'hoot'
end
if species == 'eagle'
puts 'caw'
end
if species == 'hadedah'
puts 'squawk'
end
else
raise 'there is no such thing as a quiet hadedah!' if species == 'hadedah'
end
end
def is_bird
species == 'owl' || species == 'eagle' || species == 'hadedah'
end
end