+ 10
Is there an equivalent to python exec() in ruby?
Since I failed writing a brainfuck interpreter in python and writing a compiler would be too complicated because of loops, indents and stuff, I decided to do it in ruby, where you use the end keyword to end loops. I made a program that already turns bf code into ruby code, now I only need some function to execute it.
3 Respostas
+ 8
Found it, its just exec, but now it says permission denied... why?
+ 2
I do not know much about the Ruby eval statement, but I think it's what you're looking for.
If your code is a string, then do
eval "lambda { " + your_string + " }"
And then you can run that lambda to run your code.
sources:
https://stackoverflow.com/questions/2459170/create-a-ruby-proc-from-a-string
I think the Ruby exec() is actually the equivalent of Python's
import os
os.system()
and lots of times you need permission before running shell commands
(I'm really familiar with the Python exec() function but I'm still learning Ruby)
+ 1
@Jeff Hykin late answer, im not using ruby anymore, thanks anyways