From: Florian Gross Date: 2004-10-26T02:34:08+09:00 Subject: Re: [rcr] String#first / String#last Robert Klemme wrote: > "Florian Gross" schrieb im Newsbeitrag > news:2u4cv2F24vocaU1@uni-berlin.de... > >>Robert Klemme wrote: >> >> >>>>| |adding a to_a might be good >>>>| "to_a" works line-wise. Perhaps "explode" >>>>RCR for #chars >>> >>>This does not yield characters but strings with length 1. Note also > > that > >>>there is String#each_byte which is often sufficient. >> >>The problem with String#each_byte is that nobody wants to handle >>characters as Integers in Ruby, IMHO. (I think one-character Strings are >>preferred, because they still let you use lots of Strings useful > methods.) > > Yeah possibly. Another problem with each_byte is that byte != char for > many encodings. But AFAIK #each_byte and #split(//) share this problem. I think .split(//) works correctly (returning characters) with -Ku, but I'm not sure about #each_byte. > I believe a drawback of using "foo".split(//) is that it's less > performant: you need to create the tmp array plus all the string instances > (although they share the buffer AFAIK). Agreed, and this is a big problem in current Ruby -- we don't really need the Array if Strings themselves let you do character-based operation instead of line-based ones easily. The overhead required for individual Character Objects could on the other hand be quite low. They could also be value Objects meaning you only need one single Object per character which you then store in a big hash. Plus they would not need much of the reallocation overhead of Strings. (They would just need to support most of Strings interface.) I think it is enough for them to be a wrapper around a char-trait in C. >>>Kind regards >>> robert >> >>More regards, >>Florian Gross > > Even more regards > robert Yet more regards, Florian Gross ;)