#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 ...

Get Ruby by Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.