It's not only a good thing that Ruby works this way, it's necessary.

The s[n, 0] defines a place just before or after a character, and
often before one and after another.

So:

  t = 'hi'
  t[0,0] = '('
  t[3,0] = ')'
  t
=> "(hi)"

In your adjusted version this doesn't work. It's rather interesting
that the space between the last character and a string is not nil but
a 0-length string. This makes it possible to see beforehand if the
assignment would work. Otherwise, one would just have to wait for a
(possible) IndexError exception. It even makes sense intuitively if
you think about it a minute.

Ruby, as it happens, is designed very well.

Oh, and C doesn't really have strings. I love C but it is about the
last place I would ever look for inspiration on string handling..

On Wed, Mar 30, 2011 at 2:16 PM, Patrick Tyler
<patrick.a.tyler / gmail.com> wrote:
>
> Gary,
>
> Do you have a different way of explaining why ruby goes past the last
> possible index in the situations I asked about above?  ¨Βου νεξτιοτθατ
> Ruby's model is not at all like C's, so maybe you can help clear this up
> please?
>
> Thanks to you both!
>
> --
> Posted via http://www.ruby-forum.com/.
>