Execute an eval in a thread : eval « Development « Ruby






Execute an eval in a thread



def safe_eval(str)
  Thread.start {            # Start sandbox thread
    $SAFE = 4               # Upgrade safe level
    eval(str)               # Eval in the sandbox
  }.value                   # Retrieve result
end

 








Related examples in the same category

1.Use eval to run a statement dynamically
2.Evaluation with variable
3.eval with variable name
4.Add a new method with eval