summaryrefslogtreecommitdiff
path: root/lib/delegate.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/delegate.rb')
-rw-r--r--lib/delegate.rb26
1 files changed, 18 insertions, 8 deletions
diff --git a/lib/delegate.rb b/lib/delegate.rb
index 3bbd148e74..122a565642 100644
--- a/lib/delegate.rb
+++ b/lib/delegate.rb
@@ -87,14 +87,24 @@ def DelegateClass(superclass)
methods = superclass.public_instance_methods(true)
methods -= ::Kernel.public_instance_methods(false)
methods |= ["to_s","to_a","inspect","==","=~","==="]
- klass.module_eval <<-EOS
- def initialize(obj)
- @_dc_obj = obj
- end
- def __getobj__
- @_dc_obj
- end
- EOS
+ klass.module_eval {
+ def initialize(obj)
+ @_dc_obj = obj
+ end
+ def method_missing(m, *args)
+ p [m, *args]
+ unless @_dc_obj.respond_to?(m)
+ super(m, *args)
+ end
+ @_dc_obj.__send__(m, *args)
+ end
+ def __getobj__
+ @_dc_obj
+ end
+ def __setobj__(obj)
+ @_dc_obj = obj
+ end
+ }
for method in methods
begin
klass.module_eval <<-EOS