Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. class LazyProxy < BasicObject
  2. def self.promise(&callback)
  3. new(&callback)
  4. end
  5.  
  6. def initialize(&callback)
  7. @callback = callback
  8. end
  9.  
  10. def method_missing(method, *args, &block)
  11. __target__.send(method, *args, &block)
  12. end
  13.  
  14. def __target__
  15. @target ||= @callback.call
  16. end
  17. end
  18.  
  19. module Kernel
  20. def make_a_promise(&callback)
  21. LazyProxy.promise(&callback)
  22. end
  23. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement