From: Matthias Georgi Date: 2004-05-14T19:18:58+09:00 Subject: Re: [RCR] subclasses of string as hash keys On Fri, 14 May 2004 18:08:57 +0900, Robert Klemme wrote: > This is debatable - and there *have* been lengthy debates about that. > For > example, Java's class String is declared 'final', i.e. it can't be > inherited from. I have only a slight tendency to not do it but I agree > that there might be situations where subclassing is the more appropriate > option. Though it seems to me that they are rather rare than common. e.g. a class which represents the an object id, the object id have to be a string , because it's stored in database. So to get a part of the id, you define an accessor, which scans the string. But from a practical view, I'd rather go with some module_functions, because the conversions all over the code like String#to_oid are too messy. > > Note also, that with Delegator you can quite easily wrap a String and add > functionality as you see fit. Yes, but when it comes to binary representation, I have to call everywhere to_s, also not beatyful. > >> but the easiest way is to extend class String. >> namespaces would be really good solution for that. > > How exactly would namespaces solve this problem? The term namespace is possibly wrong, but my idea is: namespace MyNames class String # makes a copy of String class end s = "xxx" # constructor of MyNames::String is called end Same thing for every string creation. But that would require a lot of change in the interpreter, every rb_str_new() must know the current namespace. Recently I attended a lecture of the creator(Erik Ernst) of the language gbeta, which solves this problem nicely, but from a very different approach. -- Matthias Georgi matti_g@gmx.de