From: Florian Gross Date: 2005-03-24T00:29:49+09:00 Subject: Re: Iterating through a string and removing leading characters Randy Kramer wrote: > On Wednesday 23 March 2005 04:04 am, Robert Klemme wrote: > >>The internal buffer (the characters) is shared but there is a new Ruby >>instance each time you invoke String#[]: > Oh, yeah, thanks--I could/should have tried that. ;-) > > Aside: but: > > irb(main):005:0> 10.times { puts s1[2].id } > 211 [times ten] > => 10 > irb(main):006:0> > > Which (maybe) looks nicer/more reasonable, except I don't know why the 3 digit > ID in this case. string[number] returns either nil or the ASCII number of the character at that place. So "foo"[0] == ?f. And the object_id of low Fixnums is usually very low as their value is directly stored in it. You can work around this by instead doing "foo"[0, 1] which will return "f". I think this behavior is subject to change in Rite, but it's not yet clear what it will change to.