From: Mark Slagell Date: 2001-02-26T12:21:27+09:00 Subject: [ruby-talk:11560] Re: Bottles of Beer finally in Ruby Okay, my turn. ============================================================================ class BeerShelf def initialize( bottles ) @stock = bottles end def take_one_down @stock -= 1 if @stock > 0 end def inventory if got_beer? "#{@stock} bottle" + ((@stock==1) ? "" : "s") + " of beer" else "No more bottles of beer" end end def got_beer? @stock > 0 end end shelf = BeerShelf.new( 100 ) while shelf.got_beer? puts shelf.inventory + " on the wall," puts shelf.inventory + "," shelf.take_one_down puts "You take one down, pass it around," puts shelf.inventory + " on the wall." puts end puts "*burp!*" ============================================================================ -- Mark