+ 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

13th Jun 2018, 2:07 PM
Vishal Pal❄️⚛️
Vishal Pal❄️⚛️ - avatar
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)
13th Jun 2018, 3:14 PM
Mickel
Mickel - avatar
+ 6
thank you Mickel Sánchez
13th Jun 2018, 5:06 PM
Vishal Pal❄️⚛️
Vishal Pal❄️⚛️ - avatar