+ 5
How could i use eval() function in eval
For my latest code, I wanted to use the eval() statement in eval(). example:: https://code.sololearn.com/cvpckGx9VFyV/?ref=app So that I can print the code and its output
2 Antworten
+ 6
What happens is that the puts function returns nil, that's why you have that error.
An alternative is to use the p function, which prints and returns the string.
Another point to keep in mind is that what is inside the eval() function must be in quotation marks:
exec = 'eval("p \" this is a string \"")'
puts "Input\n"
puts exec
puts "Output\n"
eval(exec)
+ 6
thank you Mickel Sánchez