Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class LazyProxy < BasicObject
- def self.promise(&callback)
- new(&callback)
- end
- def initialize(&callback)
- @callback = callback
- end
- def method_missing(method, *args, &block)
- __target__.send(method, *args, &block)
- end
- def __target__
- @target ||= @callback.call
- end
- end
- module Kernel
- def make_a_promise(&callback)
- LazyProxy.promise(&callback)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement