Skip to content

Instantly share code, notes, and snippets.

@qoobaa
Created April 1, 2010 16:32
Show Gist options
  • Save qoobaa/352049 to your computer and use it in GitHub Desktop.
Save qoobaa/352049 to your computer and use it in GitHub Desktop.
class Proxy < defined?(BasicObject) ? BasicObject : Object
instance_methods.each { |m| undef_method(m) if m.to_s !~ /^__/ }
def initialize(target, options = {}, &block)
@proxy_owner = options[:owner]
@proxy_target = target
extends = Array(options[:extend])
extends << ::Module.new(&block)
extends.each { |m| m.send(:extend_object, self) }
end
def proxy_target
@proxy_target
end
def proxy_owner
@proxy_owner
end
def method_missing(name, *args, &block)
@proxy_target.send(name, *args, &block)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment