Guest User

Untitled

a guest
Jul 22nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. class Sandbox
  4.  
  5. @@call = -> this, method, *args do
  6. this.method(method).call(*args)
  7. end
  8.  
  9. def self.method_added name
  10. super
  11. return if name == :initialize || @adding
  12. @adding = true
  13. alias_method (name.to_s + '_orig'), name
  14. remove_method name
  15. define_method(name, ->(*args) do
  16. @@call[self, name.to_s + '_orig', *args]
  17. end)
  18. @adding = false
  19. end
  20.  
  21. def initialize
  22. Thread.abort_on_exception = true
  23. Thread.new do
  24. $SAFE = 4
  25.  
  26. eval "test"
  27.  
  28. end.join
  29. rescue StandardError, SecurityError
  30. puts $!
  31. end
  32.  
  33. def test
  34. puts "hello"
  35. end
  36.  
  37. end
  38.  
  39. Sandbox.new
Add Comment
Please, Sign In to add comment