Re: [Rails] Variable + string to specify variable

2014-07-31 Thread Rob Biedenharn
On 2014-Jul-30, at 10:59 , Eric Saupe ericsa...@gmail.com wrote: To expand on what Scott is saying here is some code that gives an example of what he is referring to. id = 100 x = rand(1..3) arrays = [Array.new, Array.new, Array.new] selected_array = arrays[x] selected_array.push(id)

Re: [Rails] Variable + string to specify variable

2014-07-31 Thread Eric Saupe
I knew there would be a nice simpler Ruby way. I love the second solution, Rob. Below is the updated example. id = 100 arrays = [Array.new, Array.new, Array.new] arrays.sample.push(id) On Thursday, July 31, 2014 8:45:33 AM UTC-6, Rob Biedenharn wrote: On 2014-Jul-30, at 10:59 , Eric Saupe

Re: [Rails] Variable + string to specify variable

2014-07-31 Thread Scott Ribe
On Jul 31, 2014, at 10:00 AM, Eric Saupe ericsa...@gmail.com wrote: I knew there would be a nice simpler Ruby way. I love the second solution, Rob. Below is the updated example. One tiny note, this is purely a matter of style taste, spelling it out vs concision, but I thought it might be

Re: [Rails] Variable + string to specify variable

2014-07-31 Thread Rob Biedenharn
You can simplify the arrays construction, too: (with slight reformatting of the arrays output) irb2.1.1 arrays = Array.new(3) { Array.new } #2.1.1 = [[], [], []] irb2.1.1 100.times {|id| arrays.sample.push(id) } #2.1.1 = 100 irb2.1.1 arrays #2.1.1 = [[0, 2, 6, 8, 9, 11, 14, 16, 17, 18, 22,

Re: [Rails] Variable + string to specify variable

2014-07-30 Thread Eric Saupe
To expand on what Scott is saying here is some code that gives an example of what he is referring to. id = 100 x = rand(1..3) arrays = [Array.new, Array.new, Array.new] selected_array = arrays[x] selected_array.push(id) On Tuesday, July 29, 2014 8:05:16 PM UTC-6, Scott Ribe wrote: On Jul

[Rails] Variable + string to specify variable

2014-07-29 Thread Dave Castellano
Hi, Novice question: I need to assign an item id to one of 3 arrays randomly but can't figure out how to specify the correct array by combining arr and the randomly generated number... id = 100 x = rand(1..3) arr1 = Array.new arr2 = Array.new arr3 = Array.new selected_array = #{'arr' + x}

Re: [Rails] Variable + string to specify variable

2014-07-29 Thread Scott Ribe
On Jul 29, 2014, at 7:33 PM, Dave Castellano li...@ruby-forum.com wrote: Novice question: I need to assign an item id to one of 3 arrays randomly but can't figure out how to specify the correct array by combining arr and the randomly generated number... id = 100 x = rand(1..3) arr1 =