Friday, 6 September 2013

Quick way to get all of the items in a select list as an array of strings?

Quick way to get all of the items in a select list as an array of strings?

I have a page with a select list that contains a very large number of items.
I want to get all the items it contains (as String objects) and stick them
into an Array.
Select#options returns an OptionsCollection, which means the best I've
been able to come up with so far is this:
my_huge_select_list.options.each { |opt| text_array << opt.text }
...but, WOW, is that ever slow!
Is there some faster way to do the same thing?

No comments:

Post a Comment