From: Robert Klemme Date: 2011-03-12T18:46:58+09:00 Subject: Re: Array question. On 11.03.2011 23:17, Catsquotl wrote: > Hi, > I have a csv file. #several really > That file is fed to the @points variable (see below) when creating an > instance of the class. > I'd like b[5] to hold an array of all remaining records in the file left > on that line. > Now it just pushes the 5th record. I can add b[6] which will get the > next record. But The number of records left vary.... > > I am building my app slowly. i'd like to be able to get the same > functionality somewhere in the middle also. > as i have 3 fixed variables in my Acupunt class and 2that can have more > than 1 value. I am guessing i have to look at a new approach here. > ---------------------------------------------- > def set_punten > @punten=[] > File.open("#{@points}", "r").each {|e| The string interpolation is pointless here. If @points may be anything you can do @points.to_s which is still more efficient in case it is actually a String. Btw, you do not close the file handle properly! It's easier doing File.foreach @points do |e| ... end > e.chomp! > b=e.split(";") > @punten.push(Acupunt.new(b[0],b[1],b[2],b[3],b[4],b[5])) @punten.push(Acupunt.new(b[0],b[1],b[2],b[3],b[4],b[5..-1])) > } > end > ----------------------- > any suggestions? You could also use CSV class from standard library to get rid of the need for parsing. See "ri CSV", e.g. CSV.foreach(@points, :col_sep => ';') do |b| ... end Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/