#count set to 10 for the abbreviated version, just uncomment the count = 99 below and comment out the other one for the full version.
#count = 99
count = 10
command = ' '
while count != 0
puts count.to_s+ ' bottles of beer on the wall, ' +count.to_s+ ' bottles of beer!'
count = count - 1
puts 'You take one down and pass it around, ' +count.to_s+ ' bottles of beer on the wall.'
sleep 1
puts ' '
end
puts 'No more beer on the wall, No more beer.'
puts 'The guys fall down, I stagger around. No more beer to be found.'
puts ' '
while command.downcase != 'quit'
puts 'Please type quit to exit this program.'
command = gets.chomp
end
"\r\n" ### expands escapes, subs, format str, etc
'\r\n' ### does not expand and is literal
[Sat Jul 18 04:44:39 Strakc@li101-39:~ ] $ ruby testing2.rb
test.
test2
[Sat Jul 18 04:44:45 Strakc@li101-39:~ ] $
99.downto(0) {|i| puts i}
class BeerSinger
attr_reader :count
def initialize count
@count = count
end
def sing_line
if @count > 0
puts "#@count bottles of beer on the wall, #@count bottles of beer!\r\n"
remove_beer
puts "You take one down and pass it around, #@count bottles of beer on the wall.\r\n"
sleep 1
else
puts "No more beer on the wall, No more beer.\r\n"
puts "The guys fall down, I stagger around. No more beer to be found.\r\n"
sleep 1
end
end
def remove_beer
@count -= 1
end
end
puts "How many beers are on the wall?"
bs = BeerSinger.new(gets.chomp.to_i)
bs.count.downto(0) {bs.sing_line}