From: Jesús Gabriel y Galán on 28 Jul 2010 07:17 On Wed, Jul 28, 2010 at 1:10 PM, Robert Klemme <shortcutter(a)googlemail.com> wrote: > Use Array#insert. Amazing how I missed that, given that I was specifically looking for it in the rdoc :D I call "sleep deprived", or something Jesus.
From: Dave Castellano on 28 Jul 2010 08:26 Jesús Gabriel y Galán wrote: > On Wed, Jul 28, 2010 at 1:10 PM, Robert Klemme > <shortcutter(a)googlemail.com> wrote: > >> Use Array#insert. > > Amazing how I missed that, given that I was specifically looking for > it in the rdoc :D > I call "sleep deprived", or something > > Jesus. That works for single dimension arrays but I can't figure out the syntax for multi... I have been trying to use "answer_choices.insert" but cannot figure out the syntax eg answer_choices.insert([x][1],correct_ans_1) does not work.. Could you give me an example of Array#insert. using multidim. array Thanks, DC -- Posted via http://www.ruby-forum.com/.
From: Jesús Gabriel y Galán on 28 Jul 2010 09:11 On Wed, Jul 28, 2010 at 2:26 PM, Dave Castellano <dcastellano1(a)wideopenwest.com> wrote: > Jesús Gabriel y Galán wrote: >> On Wed, Jul 28, 2010 at 1:10 PM, Robert Klemme >> <shortcutter(a)googlemail.com> wrote: >> >>> Use Array#insert. >> >> Amazing how I missed that, given that I was specifically looking for >> it in the rdoc :D >> I call "sleep deprived", or something >> >> Jesus. > > That works for single dimension arrays but I can't figure out the syntax > for multi... > > I have been trying to use "answer_choices.insert" but cannot figure out > the syntax > eg answer_choices.insert([x][1],correct_ans_1) does not work.. > > Could you give me an example of Array#insert. using multidim. array In order to better understand it, I'm afraid you will need to stop thinking about multidimensional arrays, and start thinking of arrays of arrays. First you need to get the inner array: answer_choices[x] then you get back an array. It's on this inner array where you want to insert, so (split in two steps): inner = answer_choices[x] inner.insert(0, correct_ans_1) Jesus.
From: Dave Castellano on 28 Jul 2010 09:22
Dave Castellano wrote: > Jesús Gabriel y Galán wrote: >> On Wed, Jul 28, 2010 at 1:10 PM, Robert Klemme >> <shortcutter(a)googlemail.com> wrote: >> >>> Use Array#insert. >> >> Amazing how I missed that, given that I was specifically looking for >> it in the rdoc :D >> I call "sleep deprived", or something >> >> Jesus. > > That works for single dimension arrays but I can't figure out the syntax > for multi... > > I have been trying to use "answer_choices.insert" but cannot figure out > the syntax > eg answer_choices.insert([x][1],correct_ans_1) does not work.. > > Could you give me an example of Array#insert. using multidim. array > > Thanks, > > DC Sorry, missed your reply earlier. That was what I needed. Thank you for the help! DC -- Posted via http://www.ruby-forum.com/. |