From: Pit Capitain Date: 2006-12-06T06:06:35+09:00 Subject: Re: Method Namespace Trans schrieb: > I have need for a general purpose simple namespace construction. > ... > This words EXCEPT when super is called in the method (see the > test case a the bottom). > ... Tom, could you try this version? def namespace( mod, &blk ) # If block is given then create a module, otherwise # get the name of the module. if block_given? name = mod.to_s mod = Module.new(&blk) else name = mod.basename.downcase mod = mod.dup end # Include the module. This is neccessary, otherwise # Ruby won't let us bind the instance methods. include mod # Save the instance methods of the module and # replace them with a "transparent" version. methods = {} mod.instance_methods(false).each do |m| methods[ m.to_sym ] = mod.instance_method(m) mod.instance_eval do define_method(m) do super end end end # Add a method for the namespace that delegates # via the Functor to the saved instance methods. define_method(name) do Functor.new(methods) do |op, mtab, *args| mtab[op].bind(self).call(*args) end end end Regards, Pit