From: Matthias Georgi Date: 2004-05-15T01:09:34+09:00 Subject: Re: [RCR] subclasses of string as hash keys On Fri, 14 May 2004 21:28:52 +0900, Robert Klemme wrote: > This will create lots of errors. Assume someone has any instance from > namespace A and invokes to_s on that instance. He expects a String but > he > gets a A::String which doesn't even support the same interface. Bang! > This automated changing of string literals to something else is complete > nonsense. OK, I went wrong. Forget about the literals. That's not solving the problem. Let me formulate in one sentence: I just want to extend the String class with my own methods, but only if the methods get called inside my namespace. There is currently no solution to this, and there are lot of people, who are extending standard classes. I can think of a dynamic approach. I'm looking up the method table of my object at call time: 1. inside current namespace 2. if not found, then proceed with outer namespace 3. lookup method in table, if not found => proceed with outer namespace The question is how to define the method table (modules?) and also how to make it efficient. > Plus, you'd have to explain how you implement A::String if > "xxx" is already a A::String. You would have to write a C extension to > handle memory management etc. since you don't have access to the standard > String here. etc. pp. > Sorry, I didn't want an object with a different class, only with extended interface. > That's possible in all OO languages - even with Ruby. The crucial point > is how usage of this type is regulated. It was possibly not a good comparison ,because gbeta is statically typed. > > It seems to me you're stuck in some dead end street. Better sleep a > night > over this. Oh yes, I'll do and dreaming about namespaces :) -- Matthias Georgi matti_g@gmx.de