Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Bottles
- def verse(part)
- "#{bottle(part)[0]} of beer on the wall, #{bottle(part)[1]} of beer.\n".capitalize() +
- "#{part == 0 ? "Go to the store and buy some more" : "Take #{part == 1 ? "it" : "one"} down and pass it around"}" +
- ", #{bottle(part)[2]} of beer on the wall.\n"
- end
- def verses(first_verse, second_verse)
- final_string = ""
- array = build_array(first_verse, second_verse)
- array.each_with_index do |part, index|
- final_string += verse(part)
- break if index == array.length - 1
- final_string += "\n"
- end
- final_string
- end
- def song
- verses(99, 0);
- end
- def build_array(start_num, end_num)
- array = []
- start = start_num
- counter = 0
- while start != end_num - 1
- array[counter] = start
- start = start - 1
- counter = counter + 1
- end
- array
- end
- def number_wheel(number)
- return 99 if number == 0
- number - 1
- end
- def bottle(amount)
- first = amount
- second = amount
- last = number_wheel(amount)
- [singular_or_plural(first), singular_or_plural(second), singular_or_plural(last)]
- end
- def singular_or_plural(number)
- return "no more bottles" if number == 0
- number == 1 ? "#{number} bottle" : "#{number} bottles"
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement