From: Robert Dober Date: 2007-05-15T23:34:45+09:00 Subject: Re: Why was the "Symbol is a String"-idea dropped? On 5/15/07, Robert Klemme wrote: > On 15.05.2007 15:54, Robert Dober wrote: > > On 5/15/07, Brian Candler wrote: > > > >> But then what you want are not symbols, but true immutable strings. By > >> that > >> I mean: some object where I can write 10MB of binary dump. If I want > >> to add > >> one character to the end of it, then I create another object containing > >> 10MB+1byte of binary dump, and the old 10MB object is garbage-collected. > > But of course we have immutable strings already :))) > > > > class IString < String > > def initialize str > > super(str) > > freeze > > end > > end > > What advantages does this have over using "freeze" directly? Dunno :) x = IString.new("Hello World") # Not even tested yet vs. x="HelloWorld".freeze Well the first one has the advantage that I thought about it ;) Now I reckon that the subclass stuff is baaad def blah str raise ArgumentError unless IString === str ... end but now someone does class MString < IString get rid of the freeze (by calling superclass.superclass.new in self.class.new e.g) end and my code is broken, while in def blah str raise ArgumentError unless str.respond_to? :frozen && str.frozen? ... end frozen is frozen forever. So do what Robert told you and beware of what Robert told you;) > > str = "foo".freeze > > It seems using a new class will increase the likelihood of things to break. > > > HTIOI (Hope this is of interest ;) > > LOL > > > You see things; and you say Why? > > But I dream things that never were; and I say Why not? > > -- George Bernard Shaw > > Greetings to George, btw. :-) Well last time I met him he was admiring your posts to the list :-P > > robert > > idem