From: Paul Brannan Date: 2002-09-12T00:01:33+09:00 Subject: Re: how to make proxy objects On Wed, Sep 11, 2002 at 07:27:16PM +0900, Tom Sawyer wrote: > class Module > public :undef_method > end > > class Proxy_Object > def initialize(peer, oid) > methods.each { |mid| > if not ['inspect', > 'instance_eval', > 'instance_variables', > '__id__', > 'id', > 'new', > 'methods', > 'method_missing', > 'undef_method', > 'class', > '__send__', > 'send'].include?(mid) I think this belongs in the body of the class definition, and not in the constructor; otherwise, you have to iterate over all the methods in Proxy_Object every time you create a new Proxy_Object; this will slow down construction (the same problem that plagues SimpleDelegator). Also, new() and undef_method() are class methods and not instance methods, so I don't think they belong in this list. If you don't override inspect(), it might be nice to still be able to inspect the remote object. Note that Ruby's Delegate takes a slightly different approach; instead of keeping a static list of preserved methods, it assumes that all methods in Kernel will be preserved except 6 specific methods. You might also want to look at drb and see how its proxy objects are implemented. > self.class.undef_method(mid.intern) Instead of making undef_method public, you could use: self.class.instance_eval { undef_method(mid.intern) } If you move the entire loop outside initialize(), then you can call it directly: undef_method(mid.intern) > end > } > end > > def method_missing(mid, *args) > ...act as proxy... > end > end