0
How can i convert a str value to a var. name and print it !?
Hi there, i have just found a difficulty in converting a string value to a variable name for example : a1=1 a2=2 a3=3 a4=4 a5=5 a6=6 g="a" for k in (1..6) puts g+k.to_s end #as you see it will print a str value but i want to convert it to the variables name # to print their values
1 Respuesta
0
Hi,
you can do that using a binding method (see linked code).
Keep in mind that this is not best practice. Using it for error analysis might help, but for production purposes better use arrays or other data structures solving your problem.
https://code.sololearn.com/cIAw979K1Kk0/?ref=app