From: ts Date: 2002-12-15T00:59:12+09:00 Subject: Re: Is it wise to extend Matrix? >>>>> "J" == Jim Freeze writes: J> Sorry, but being new to delegators, can you show an example of "but must J> return an object which is a delegator..." Here what do DelegateClass in delegate.rb def DelegateClass(superclass) klass = Class.new methods = superclass.instance_methods(true) methods -= ::Kernel.instance_methods methods |= ["to_s","to_a","inspect","==","=~","==="] klass.module_eval <<-EOS def initialize(obj) @obj = obj end EOS for method in methods klass.module_eval <<-EOS def #{method}(*args, &block) begin @obj.__send__(:#{method}, *args, &block) rescue $@[0,2] = nil raise end end EOS end return klass; end All wrapped function return the result of @obj.__send__(:#{method}, *args, &block) where @obj in your case is a Matrix Object When you write m = MyMatrix[[1,2],[3,4]] n = MyMatrix[[1,2],[3,4]] o = m + n ruby will call the method #+ for @obj which is a Matrix and fatally the result is a Matrix when you want an instance of MyMatrix Guy Decoux