From: Brian Candler Date: 2009-06-04T04:28:51+09:00 Subject: Re: assign the array returned by String.split to a variable Catsquotl wrote: > Hi > > i have the following method > ----- > def create > length = @txt.length > i = 0 > while i < (length + 1) > line = @txt[i] > line.split(',') > #@arr.push(a) > i += 1 > end > end > ------- > this works but as soon as i take out the comment. > i get an error something about private method split beeing called on a > nil object. This means that @arr is nil, that is, you are doing nil.push(a) So you need to initialize it first: @arr = [] There are a few other errors in your code, for example you didn't assign to a: a = line.split(',') @arr.push(a) and your loop should be while i < length, not while i < length+1. As has been pointed out, there are more ruby-like ways to do this loop. -- Posted via http://www.ruby-forum.com/.