Skip to content

Instantly share code, notes, and snippets.

@tejo
Created November 17, 2014 10:10
Show Gist options
  • Save tejo/04bfc5458a23043f0d8c to your computer and use it in GitHub Desktop.
Save tejo/04bfc5458a23043f0d8c to your computer and use it in GitHub Desktop.
class Album
attr_accessor :band, :title, :year, :tracks
def initialize(title, band, year)
@title = title
@band = band
@year = year
@tracks = []
end
def add_track(track)
@tracks << track
end
def total_duration
@tracks.map(&:duration).reduce(:+)
end
def print_booklet
puts "title: #{title}"
puts "band: #{band}"
puts "year: #{year}"
puts "total play time: #{total_duration}"
puts "track list"
puts "\n"
@tracks.each do |track|
puts "#{track.title} #{track.duration}"
end
puts "------------------------------"
end
end
class Track
attr_accessor :title, :duration
def initialize(title, duration)
@title = title
@duration = duration
end
end
album = Album.new('La sottile linea grossa', 'Nemesi', '2014')
album.add_track(Track.new('Fenice', 270))
album.add_track(Track.new('Cara Barbara', 300))
album2 = Album.new('Solo Franco', 'Franco Califano', '1972')
album2.add_track(Track.new('Tutto il resto è noia', 270))
album2.add_track(Track.new('Solo gatti', 123))
album.print_booklet
album2.print_booklet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment