Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- class Sandbox
- @@call = -> this, method, *args do
- this.method(method).call(*args)
- end
- def self.method_added name
- super
- return if name == :initialize || @adding
- @adding = true
- alias_method (name.to_s + '_orig'), name
- remove_method name
- define_method(name, ->(*args) do
- @@call[self, name.to_s + '_orig', *args]
- end)
- @adding = false
- end
- def initialize
- Thread.abort_on_exception = true
- Thread.new do
- $SAFE = 4
- eval "test"
- end.join
- rescue StandardError, SecurityError
- puts $!
- end
- def test
- puts "hello"
- end
- end
- Sandbox.new
Add Comment
Please, Sign In to add comment