When I run the command I get all the song names and then the instances following it. How do I only get the names?
class Song
@@all = []
attr_accessor :name
def initialize(name)
@name = name
@@all << self
end
def self.all
@@all
end
def self.print_all_song_names
@@all.each do |song|
puts song.name
end
end
end
hotline_bling = Song.new("Hotline Bling")
thriller = Song.new("Thriller")
ninety_nine_problems = Song.new("99 Problems")
thriller = Song.new("Thriller")
puts Song.print_all_song_names
Which outputs:
Hotline Bling
Thriller
99 Problems
Thriller
#<Song:0x00000000058ced30>
#<Song:0x00000000058cecb8>
#<Song:0x00000000058cebc8>
#<Song:0x00000000058ceb50>