-
-
Save anonymous/79dee1aae800de3da00e2d98f972d18e 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
What it the artist name ?:>1 | |
What is the song name ?:>2 | |
library.rb:32:in `add_song': undefined method `<<' for nil:NilClass (NoMethodError) | |
from library.rb:59:in `<main>' |
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
module Menu | |
puts "Hello ! This is an amazing app for organizing your music ! This is a | |
cool library ! It allows you to do multiple tasks | |
What would you like to do ? | |
-- 1 add a music ? | |
-- 2 delete a music ? | |
-- 3 delete an album ? | |
" | |
end | |
module Promptable | |
def prompt(message = "What music would you like to add", symbol = ":>") | |
print message | |
print symbol | |
gets.chomp | |
end | |
end | |
class Library | |
attr_accessor :artist, :song | |
def initialize | |
@library = {} | |
end | |
def add_artist(artist) | |
@library[artist] = [] | |
end | |
def add_song(song) | |
@library[artist] << song | |
end | |
def show | |
puts @library | |
end | |
end | |
class Artist | |
attr_accessor :name, :song | |
def initialize(artist) | |
@name = artist[:name] | |
@song = artist[:song] | |
end | |
def to_s | |
"#{name}, #{song}" | |
end | |
end | |
if __FILE__ == $PROGRAM_NAME | |
include Promptable | |
include Menu | |
my_library = Library.new | |
my_library.add_artist(Artist.new(:name => prompt("What it the artist name ?"))) | |
my_library.add_song(Artist.new(:song => prompt("What is the song name ?"))) | |
my_library.show | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment