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