Skip to content

Instantly share code, notes, and snippets.

@luikore
Created June 24, 2009 15:23
Show Gist options
  • Save luikore/135335 to your computer and use it in GitHub Desktop.
Save luikore/135335 to your computer and use it in GitHub Desktop.
99 bottles of beer
# 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