Skip to content

Instantly share code, notes, and snippets.

@octosteve
Created July 3, 2012 03:57
Show Gist options
  • Save octosteve/3037544 to your computer and use it in GitHub Desktop.
Save octosteve/3037544 to your computer and use it in GitHub Desktop.
First go
class Artist
attr_accessor :name, :songs, :genres
@@artists = []
def initialize
@@artists << self
@songs = []
@genres = []
end
def self.reset_artists
@@artists.clear
end
def self.count
@@artists.count
end
def self.all
@@artists
end
def add_song(song)
songs << song
if song.genre
genres << song.genre
song.genre.artists << self
end
end
def songs_count
songs.count
end
end
class Song
attr_accessor :genre
def genre=(genre)
genre.songs << self
@genre = genre
end
end
class Genre
require 'set'
attr_accessor :name, :songs, :artists
@@genres = []
def initialize
@@genres << self
@songs = []
@artists = Set.new
end
def self.reset_genres
@@genres.clear
end
def self.all
@@genres
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment