Skip to content

Instantly share code, notes, and snippets.

@jimmycuadra
Created January 5, 2011 04:49
Show Gist options
  • Save jimmycuadra/765942 to your computer and use it in GitHub Desktop.
Save jimmycuadra/765942 to your computer and use it in GitHub Desktop.
Discography: An exercise to learn some basic Ruby
# Write some classes to keep track of an artist's discography. Start by creating an
# artist, then an album, then songs. Add songs to the album and then add the
# album to the artist. Finally, call the discography method on the artist
# to print out a nice formatted string detailing that artist's discography.
# You should be able to use it like this:
nebyoolae = Artist.new('Nebyoolae')
cs13 = Album.new('Clocks Striking 13')
cs13.songs << Song.new('Awakening', '5:01')
cs13.songs << Song.new('The Mistaken', '4:30')
the_matic = Album.new('The Matic')
the_matic.songs << Song.new('The Sea Castle', '2:25')
the_matic.songs << Song.new('My Chamber Life', '2:20')
nebyoolae.albums << cs13
nebyoolae.albums << the_matic
puts nebyoolae.discography
# The output should be:
# Nebyoolae - Clocks Striking 13: Awakening (5:01), The Mistaken (4:30) - The Matic: The Sea Castle (2:25), My Chamber Life (2:20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment