new(obj)
public
Pass in the obj to delegate method calls to. All methods supported
by obj will be delegated to.
Show source
def initialize(obj)
preserved = ::Kernel.public_instance_methods(false)
preserved -= ["to_s","to_a","inspect","==","=~","==="]
for t in self.class.ancestors
preserved |= t.public_instance_methods(false)
preserved |= t.private_instance_methods(false)
preserved |= t.protected_instance_methods(false)
break if t == Delegator
end
preserved << "singleton_method_added"
for method in obj.methods
next if preserved.include? method
begin
eval "def self.\#{method}(*args, &block)\nbegin\n__getobj__.__send__(:\#{method}, *args, &block)\nensure\n$@.delete_if{|s|IgnoreBacktracePat=~s} if $@\nend\nend\n", nil, __FILE__, __LINE__+1
rescue SyntaxError
raise NameError, "invalid identifier %s" % method, caller(4)
end
end
end