forked from DPI-WE/sample-technical-interview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbirthday_cake.rb
69 lines (54 loc) · 1.36 KB
/
birthday_cake.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
=begin
birthday_cake.rb
It's your birthday! Yay! 🎂
Can you debug this BirthdayCake class in time to sing happy birthday? 🎶
Tip: Resolve the error messages before trying to make it work
Expected output:
Happy 10th Birthday!
Birthday cake with 10 blown out candles
Lighting candles...
Birthday cake with 10 lit candles
Singing happy birthday...
🎶Happy birthday to you, happy birthday to you🎶
Blowing out candles...
Birthday cake with 10 blown out candles
=end
require "active_support"
class BirthdayCake
attr_accessor :age, :lit
def initialize(age)
self.age = age
self.lit = false
end
def candles_status
if self.lit == true
return "lit"
else
return "blown out"
end
end
def greet
"Happy #{self.age.ordinalize} Birdday!"
end
def sing
"🎶Happy birthday to you, happy birthday to you🎶"
end
def to_s
"Birthday cake with #{self.age} #{candles_status} candles"
end
def BirthdayCake.celebrate(age)
birthday_cake = Birthdaycake.new(age)
puts birthday_cake.greet
puts birthday_cake.to_s
puts "Lighting candles..."
birthday_cake.light_candles
puts birthday_cake.to_s
puts "Singing happy birthday..."
puts birthday_cake.sign
puts "Blowing out candles..."
birth_cake.blow_out_candles
puts birthday_cake.to_s
birthday_cake
end
end
BirthdayCake.celebrate(10)