If I have a variable of a basic String/integer/float value, or a hash/array of these basic values, how to get its expression as a String?
If it is a string, I want '"foo"'. If it is an Integer, I want "1".
Basically I want the opposite of eval(). Currently I use inspect but it feels fragile.
Update:
I need to take user input, and output a .rb file containing that input. For exmple this erb file:
a = <%= variable %>
So if a user input a string, then in the .rb file I need to include that string in Ruby expression, e.g. a = "foo" or a = 1.
#inspectis exactly what you want.