From: Alexey Borzenkov Date: 2009-04-05T23:55:19+09:00 Subject: Re: parsing a file's contents Ant 23 wrote: > Hello all, I'm relatively new to ruby and this forum so I'm not sure I'm > posting this in the right area but here goes. My problem is I have a > file I want to read in, the file contains numbers in a CSV set-up like > so: 2, 3, 15, 25, 29 the numbers are all written out like that 5 per > row. What I want to do is split the numbers into columns that the 2 and > the number under it are all in an array. The main problem I'm having is > that when I try to put the numbers into the array I get a NoMethodError > for the String type which I don't understand since I created the every > method for the Array class not String. I attached the code any > assistance is appreciated. cols = [] row = 0 file.each_line do |line| line.chomp.split(/\s*,\s*/).each_with_index do |num, col| cols[col] ||= [] cols[col][row] = num.to_i rescue nil end row += 1 end Now cols[0] contains the first column, and so on. -- Posted via http://www.ruby-forum.com/.