From: Rajinder Yadav Date: 2010-10-26T04:10:28+09:00 Subject: Re: Simplified version On Sat, Oct 23, 2010 at 8:41 PM, Paul Roche wrote: > Hi Jeremy. I'm back with a simplified version of the above problem. Here > is the code..... > > > Basically I now want to create a function that takes in data that has > been taken in from a csv file. > > So I have this on my main file....... > > songs = reader.read_in_songs(song_csv_file_name) > > puts "\nBuilding Libraries..." > libs = Song.build_all(songs) > > ---------------------------------------------- > > here is the song class......... > > > class Song > attr_accessor :name, :owner > def initialize(name, owner) >  @name = name >  @owner = owner > end > > def to_s > puts " #{@name} #{@owner}" > end > > > def self.build_all(songs) > > ## I want to be able to 'create song objects'(?) from the data taken in > from the csv file here > > end > > end > > ------------------------------------------- > > Here is a rough idea I have so far, but it's returning nothing > > songs = [] your problem is that you create an empty array above, then below you iterate same empty array and push nothing into it! > songs.each {|song| songs << Song.new(song.name, song.owner)} this should get you going in the right direction, assuming your cvs list is comma separated # create a test cvs list # cvslist = [] cvslist << "song1,owner1" << "song2,owner2" << "song3,owner3" # get song and owner strings # cvslist.each do |item| song,owner = item.split /\s*,\s*/ puts song puts owner end > ------------------------------- > > Do I have the right idea? > -- Kind Regards, Rajinder Yadav | DevMentor.org | Do Good! ~ Share Freely GNU/Linux: 2.6.35-22-generic Kubuntu x86_64 10.10 | KDE 4.5.1 Ruby 1.9.2p0 | Rails 3.0.1