From: sto.mar@... Date: 2012-10-25T14:40:50+09:00 Subject: Re: Issue in reading excel using Parseexcel Am 25.10.2012 06:42, schrieb Rochit Sen: > Joel Pearson wrote in post #1080994: >> temp.push cell > > Thanks @Joel and @Chris > > I used the push method and got it working. But was wondering one thing, > that i can assign values in an array by writing the following: > > Arr = [1,2,3] > > but i cannot use var that is being iterated by a "do..end" and assign > the values of var into an array as i was doing earlier: > > row.each do |cell| > temp = cell.to_s('latin1') > end > > is my understanding correct? No. Again: what you are doing here is reassign the temp variable in every iteration (so it is always set to only the last cell content, previous assignments are irrelevant). What you want is to append elements to an existing array -> push Consider 1.9.3-p194 :001 > temp = [] 1.9.3-p194 :002 > [1,2,3].each do |element| 1.9.3-p194 :003 > temp = element # reassigns temp to some number 1.9.3-p194 :004?> p temp 1.9.3-p194 :005?> end 1 2 3 1.9.3-p194 :006 > p temp 3 as opposed to 1.9.3-p194 :001 > temp = [] 1.9.3-p194 :002 > [1,2,3].each do |element| 1.9.3-p194 :003 > temp << element # appends the number to temp array 1.9.3-p194 :004?> end 1.9.3-p194 :005 > p temp [1, 2, 3] --