Prev: Unable to access the elements in an array with array[1][0]
Next: Confused with "include" and require
From: Arti Singh on 26 Jul 2010 12:42 Thanks, James. I owe you one. I had been reading the data from the datasource incorrectly. xclworksheet.Range("A1:B20").rows.each{|r|ea_array.push(r.value.inspect) instead I should have just done ea_array=xclworksheet.Range("A1:B20")['Value'] James wrote: > On Mon, Jul 26, 2010 at 10:11 AM, Arti Singh <arti.p.singh(a)gmail.com> > wrote: > >> [["third","third value"]] >> [["third","third value"]] >> [["fifth","fifth value"]] >> >> How can I get the elements in this array? am I missing something here? >> -- >> Posted via http://www.ruby-forum.com/. >> >> You don't need double brackets to declare an array. > > ["first","first value"] > ["second","second value"] > ["third","third value"] > ["third","third value"] > ["fifth","fifth value"] > > You declared an invalid multidimensional array. To declare a > multidimensional array: > > [["first","first value"], ["second","second value"], ["third","third > value"], ["third","third value"], ["fifth","fifth value"]] > > > Your multidimensional array looks like this: > [["first","first value"]] > > The second set of brackets are closing off the first multidimensional > array. > At that point, you're trying to access array[1][0], but there's only a > zeroeth element. Remember: the first element in any array is at offset > 0, so > to access the first element of this multidimensional array: array[0][0] > > Make sense? > > James > > > > If you're declaring a multid -- Posted via http://www.ruby-forum.com/. |