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

#4 Sound File Player (shuffle_play.rb)

In this script, we’ll make a program that plays music files in a shuffled order. We explored classes in the previous example, and we’ll learn more about them here. What happens when we want to have a class that is very similar to an existing class? We have several options.

Note

This version is fairly Unix-centric. You can download a Windows version that uses the Winamp player at http://www.nostarch.com/ruby.htm.

In Ruby, we know that everything is an object, which is just another way of saying that it’s a member (or instance) of a class. We know about well-defined classes like Arrays, Strings, Integers, and so on. All of these are what we call open classes, meaning that we can add code to existing classes. For ...

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