Skip to content

Instantly share code, notes, and snippets.

@kwstannard
Created February 3, 2015 15:29
Show Gist options
  • Save kwstannard/2ae681e98bb10d33795f to your computer and use it in GitHub Desktop.
Save kwstannard/2ae681e98bb10d33795f to your computer and use it in GitHub Desktop.
Ruby Proxy
class Proxy
def self.proxy(context, &blk)
p = new(context)
p.__proxy &blk
p
end
def initialize(context)
@context = context
end
def method_missing(method, *args, &blk)
__object.send(method, *args, &blk)
end
def __proxy &blk
@blk = blk
end
def __object
@object ||= @blk.call(@context)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment