Skip to content

Instantly share code, notes, and snippets.

@adamsanderson
Created January 18, 2011 15:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamsanderson/784613 to your computer and use it in GitHub Desktop.
Save adamsanderson/784613 to your computer and use it in GitHub Desktop.
An example of using Delegator to implement Futures in ruby.
require 'delegate'
class Future < SimpleDelegator
def initialize(&block)
@_thread = Thread.start(&block)
end
def __getobj__
__setobj__(@_thread.value) if @_thread.alive?
super
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment