From: Hal Fulton Date: 2004-08-13T04:34:00+09:00 Subject: Re: How about a String#chars method? Warren Brown wrote: > Ara, > >>something like this >> >> ~ > cat b.rb >> class String >> def chars width = 1 >> unpack "a#{ width }" * (size / width + (size % width == 0 ? 0 : > > 1)) > >> end >> end > > I wish it were that easy, but multi-byte character sets are not > always fixed-width. For example, UTF-8 characters can be anywhere from > one byte to (theoretically) six bytes long. So the multi-byte handling > would have to be a little more sophisticated. And anyhow, some of this will be addressed in 2.0, so I'm not sure how much effort we want to invest in a temporary solution. Matz has his own ideas about how things will work. An each_char may or may not be added. I fear it wouldn't be trivial to implement. See Matz's reply to my post of 2 May 2004: http://ruby-talk.com/blade/99047 Hal