Created
November 4, 2016 23:01
-
-
Save clandry94/927c645f30fe1dbce17dea1e83a9fbd8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Song | |
attr_reader :name, :duration | |
def initialize(name, duration) | |
@name = name | |
@duration = duration | |
end | |
def song | |
end | |
end | |
class Album | |
attr_reader :name, :release_year, :rating, :songs | |
def initialize(name, release_year, rating, songs) | |
@name = name | |
@release_year = release_year | |
@rating = rating | |
@songs = songs | |
end | |
end | |
class Artist | |
attr_reader :name, :albums | |
def initialize(name, albums) | |
@name = name | |
@albums = albums | |
end | |
def to_s | |
output = "Artist Name: #{@name} has albums " | |
@albums.each { |album| output << "#{album.name}, "} | |
output | |
end | |
def include? album_name | |
albums.each { |album| return true if album.name == album_name } | |
false | |
end | |
end | |
# Songs from animal | |
first_song = Song.new('Dinosaur', 120) | |
second_song = Song.new('Blah Blah Blah', 160) | |
third_song = Song.new('Take It Off', 200) | |
first_song.song | |
# Songs from cannibal | |
fourth_song = Song.new('Cannibal', 120) | |
fifth_song = Song.new('We R Who We R', 200) | |
sixth_song = Song.new('Grow A Pear', 140) | |
album_one_songs = [first_song, second_song, third_song] | |
album_two_songs = [fourth_song, fifth_song, sixth_song] | |
first_album = Album.new('Animal', 2010, 5, album_one_songs) | |
second_album = Album.new('Cannibal', 2010, 4, album_two_songs) | |
albums = [first_album, second_album] | |
artist = Artist.new('Kesha', albums) | |
artist.albums.each do |album| | |
album.songs.each { |song| puts song.name } | |
end | |
puts artist.include? "Cannibal" | |
puts artist.include? "Warrior" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment