July 2011
Intermediate to advanced
400 pages
8h 46m
English
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 ...
Read now
Unlock full access