From: Mark Slagell Date: 2001-06-28T12:20:27+09:00 Subject: [ruby-talk:16986] Re: RCR for the String class David Alan Black wrote: > > 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 There's also the [position,length] substring notation. I've found this pretty easy to get used to, as it's consistent whether you want one character or several. str = "Joe" str[0,1] #-> "J" str[0,2] #-> "Jo" str[0,3] #-> "Joe" -- Mark