O'Reilly logo

Ruby by Example by Kevin C. Baird

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

#3 The 99 Bottles of Beer Song (99bottles.rb)

This script demonstrates basic Object Orientation by singing (okay, printing) the “99 Bottles of Beer” song. The content of the example may be a bit contrived, but the program itself reveals a great deal about naming conventions in Ruby. We’ll be defining a Wall, on which there are bottles, the number of which repeatedly drops by one.

Here’s the code. Classes are the basic building blocks in Ruby, so it’s worthwhile for anyone curious about the language to understand them in some depth. We’ve already seen some built-in classes (String, Integer, and Array), so they’re not a fundamentally new concept for you at this point. What is new is the ability to define completely novel classes of your own, as we ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required