Great, so with everyone's help this is what I ended up doing in the end:
foo = [1foo, 2foo, 3foo]
bar = [abar, bbar]
['foo', 'bar'].each do |this_array|
length = 0
this_obj = this_array.to_s.capitalize.constantize
until length == eval(this_array).length
this_obj.create(:word => eval(this_array)[length])
length += 1
end
the trick was to use the .constantize method to turn 'foo' and 'bar'
into classes Foo and Bar, and then to use eval() to use the array's
names instead of its contents.
I came across .constantize after searching for const_get as phrogz
suggested.
7stud, my classes are defined in their corresponding controllers - this
is a part of a Rails exercise
dusty, your method using collect and compact looks interesting, I'll
play with it too.
Thanks everyone for help. I haven't been excited about programming for
the last 15 years, but Ruby is changing that rapidly :)
--
Posted via http://www.ruby-forum.com/.