Created
June 24, 2009 15:23
-
-
Save luikore/135335 to your computer and use it in GitHub Desktop.
99 bottles of beer
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
# 99 bottles of beer | |
class Fixnum | |
def bottle | |
"#{self} bottles of beer". | |
sub(/^-1/,'99'). | |
sub(/^0/,'no more'). | |
sub(/^(1\ .+)s/, '\1') | |
end | |
def wall | |
"#{self.bottle} on the wall" | |
end | |
def take | |
self > 0 ? | |
"Take one down and pass it around" : | |
"Go to the store and buy some more" | |
end | |
end | |
99.downto 0 do |n| | |
print "#{n.wall}, #{n.bottle}.\n#{n.take}, #{(n-1).wall}.\n\n".capitalize | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment