On Jul 29, 2014, at 7:33 PM, Dave Castellano <lists@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 = Array.new
> arr2 = Array.new
> arr3 = Array.new
>
> selected_array = "#{'arr' + x}" *** Not sure how to do this ****
>
> selected_array.push(id)
>
While you could append the name and eval, that's not really a clean approach. Just use an array of arrays. Or if else...
--
Scott Ribe
scott_ribe@elevated-dev.com
http://www.elevated-dev.com/
(303) 722-0567 voice
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/4A8D974A-3F8F-449E-B0C3-83C4C3209D4B%40elevated-dev.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment