Created
March 17, 2016 01:47
-
-
Save profh/f0af560400cbcb2efe45 to your computer and use it in GitHub Desktop.
Coding template for the 99 Bottles of Beer exercise in class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Classic OOP exercise, done in Ruby | |
class Wall | |
# Set up the wall with a set of bottles. The default | |
# number of bottles is 99 | |
def initialize( ) | |
end | |
# Is the wall empty or not? This method returns true | |
# if the wall is empty and false otherwise. | |
def empty? | |
end | |
# Verse: "X bottles of beer on the wall, X bottles of | |
# beer. Take one down, pass it around, X-1 bottles of | |
# beer on the wall." | |
def sing_one_verse! | |
end | |
private | |
# The basic part of verse is the phrase "X bottle(s) | |
# of beer" with something extra at the end... | |
def sing(extra='') | |
end | |
# Need a way to reduce the number of bottles during | |
# the verse and tell that it is gone | |
def take_one_down! | |
end | |
end | |
# PUT INTO ACTION ... | |
# Now use the class to sing the song (short version) | |
wall = Wall.new(10) | |
wall.sing_one_verse! until wall.empty? | |
# NAMES: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment