Skip to content

Instantly share code, notes, and snippets.

@brandonpittman
Last active June 19, 2017 05:36
Show Gist options
  • Save brandonpittman/49c8ae7ff946b0a4de32f491b0c50e4f to your computer and use it in GitHub Desktop.
Save brandonpittman/49c8ae7ff946b0a4de32f491b0c50e4f to your computer and use it in GitHub Desktop.
99 Bottles of OOP assignment
class Bottles
def verse(number_of_bottles)
first_line(number_of_bottles) << "\n" << second_line(number_of_bottles) << "\n"
end
def verses(number_of_bottles_start, number_of_bottles_end)
number_of_bottles_start.downto(number_of_bottles_end).map do |number_of_bottles|
verse(number_of_bottles)
end.join("\n")
end
def song
verses(99, 0)
end
def singular_or_plural_bottles(number_of_bottles)
return "1 bottle" if number_of_bottles == 1
return "no more bottles" if number_of_bottles == 0
"#{number_of_bottles} bottles"
end
def first_line(number_of_bottles)
return "1 bottle of beer on the wall, 1 bottle of beer." if number_of_bottles == 1
return "No more bottles of beer on the wall, no more bottles of beer." if number_of_bottles == 0
"#{number_of_bottles} bottles of beer on the wall, #{number_of_bottles} bottles of beer."
end
def second_line(number_of_bottles)
return "Take it down and pass it around, no more bottles of beer on the wall." if number_of_bottles == 1
return "Go to the store and buy some more, 99 bottles of beer on the wall." if number_of_bottles == 0
"Take one down and pass it around, #{singular_or_plural_bottles(number_of_bottles -1)} of beer on the wall."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment