How do I use strings or symbols to create new variables || objects? Say I want 5 unique objects of an already made item class;
for x in 1..5
item_x = item.new() #where x is obviously the number value of the iterator
end
I have tried using eval() in this manner:
for x in 1..5
eval( "item_" << x << "= item.new()")
end
Hoping that putting the string I want executed into eval would have it executed as if I put it into the code.
I have searched for dynamic object creation and have not found anyone with this problem, sorry if this is mundane stuff. I have found references to people using .const_get and Openstruct but these don't seem to fix my problem in a manner I can understand.
item_xcome from!? It's not in the source code anywhere!?" I'd recommend rethinking how you can store data in a container, like an array or hash, and access the data how you need. You might want to explain the goal, and we can help you pick better structures, rather than ask for help in what isn't a good direction.