From: Robert Klemme Date: 2004-05-17T16:24:00+09:00 Subject: Re: Namespaces (was [RCR] subclasses of string as hash keys) "Matthias Georgi" schrieb im Newsbeitrag news:opr71j8uur7zr67k@mail.gmx.net... example code > Every missing method for a normal String object will be intercepted, > and the object gets extended with a module in the calling environment. > That's actually what we needs. > My own extensions are only used in my modules. > The code above is only a demonstration of the algorithm. > There is a problem left, I cannot pass the strings outside > my module, because other people are expecting the standard > String interface, so the whole thing should be integrated in the > language core without singleton classes, extending only for the > actual method call. If that functionality is only needed inside the module then IMHO there is a much easier way to accomplish this: define functions in a namespace aka define module methods: module Foo def reformat(str) str.gsub!(/^(.*)$/, '[\\1]') str end class Test include Foo def initialize(s);@s=s;end def do_something puts reformat( @s ).length end end end module Bar def reformat(str) str.gsub!(/^(.*)$/, '<<\\1>>') str end class Test include Bar def initialize(s);@s=s;end def do_something puts reformat( @s ).length end end end >> t1 = Foo::Test.new("xx") => # >> t1.do_something 4 => nil >> t2 = Bar::Test.new("xx") => # >> t2.do_something 6 => nil Regards robert