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)\nrescue Exception\n$@.delete_if{|s| /:in `__getobj__'$/ =~ s} #`\n$@.delete_if{|s| /^\\\\(eval\\\\):/ =~ s}\nKernel::raise\nend\nend\n"
rescue SyntaxError
raise NameError, "invalid identifier %s" % method, caller(4)
end
end
end