Module: Safe
- Defined in:
- lib/muzang-plugins/muzang-eval.rb
Class Method Summary collapse
Class Method Details
.safe(code, sandbox = nil) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/muzang-plugins/muzang-eval.rb', line 3 def safe(code, sandbox=nil) error = nil begin $-w = nil sandbox ||= Object.new.taint yield(sandbox) if block_given? $SAFE = 5 value = eval(code, sandbox.send(:binding)) result = Marshal.load(Marshal.dump(value)) rescue Exception => error error = Marshal.load(Marshal.dump(error)) end return result, error end |