From: David Alan Black Date: 2001-06-28T11:46:01+09:00 Subject: [ruby-talk:16984] Re: RCR for the String class Hello -- On Thu, 28 Jun 2001, Joseph McDonald wrote: > Hi, > > What does everyone thing of this as an RCR to change the behavior of > the String class? > > Basically, When I say > str = "Joe" > puts str[0] > > I want it to print "J" not the ascii code for "J". I think the need > to get the ascii code is much rarer then getting the actual character. > much rarer. It seems pragmatic to change it. Otherwise you have to > say: > puts str[0..0] > which is weird. You can do this: puts str[0].chr I don't know the rationale for the code rather than character behavior, but perhaps someone who does will comment on it. I agree that it seems slightly unexpected, but I imagine there's a history to it that would make sense of it. (Or maybe there's a future to it -- something to do with extended character sets?) > The other is, if I say: > s[2] = "seph likes ruby a lot" > > It should print out: > Joseph likes ruby a lot. It does, doesn't it? irb 1> str = "Joe" ==>"Joe" irb 2> str[2] = "seph likes ruby a lot." ==>"seph likes ruby a lot." irb 3> str ==>"Joseph likes ruby a lot." David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav