A YAML Database

For an example of a slightly more complicated application that saves and loads data in YAML format, take a look at the cd_db.rb sample program. This implements a simple CD database. It defines three types of CD objects: a basic CD that contains data on the name, artist, and number of tracks; and two more specialized descendants, PopCD, which adds data on the genre (for example, rock or country), and ClassicalCD, which adds data on the conductor and composer:

cd_db.rb

class CD def initialize( arr ) @name = arr[0] @artist = arr[1] @numtracks = arr[2] end def getdetails return[@name, @artist, @numtracks] end end class PopCD < CD def initialize( arr ) super( arr ) @genre = arr[3] end def getdetails return( super << @genre ) end end class ...

Get The Book of Ruby now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.