That sounds very clear and a good idea to me, except for the whole
str[pos] = "string"
where str from pos on is replaced by "string".  That might be better if
it inserted the string, but not replace the contents.  Of course, then you
havet he issue that one expects str[pos] = "c" to simply replace str at pos
with "c".

Maybe I should shut up now, but you guys get my general drift, right?

On Thu, Jun 28, 2001 at 11:29:41AM +0900, 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.
> 
> The other is, if I say:
> s[2] = "seph likes ruby a lot"
> 
> It should print out:
> Joseph likes ruby a lot.
> 
> Why should the programmer have to worry about getting the new strings
> length?
> 
> In the spirit of Guy Decoux, I have a b.rb to sort of explain what I
> am proposing:
> 
> joe@merry:~$ cat b.rb
> #!/usr/local/bin/ruby
> 
> class BetterString < String
> 
>   def [] (*args)
>     if (args.length == 1 and args[0].kind_of?Fixnum)
>       super(args[0]..args[0])
>     else
>       super(*args)
>     end
>   end
> 
>   def []= (*args)
>     if (args.length==2 and args[0].kind_of?Fixnum and args[1].kind_of?String)
>       super(args[0], args[0]+args[1].length, args[1])
>     else
>       super(*args)
>     end
>   end
> end
> 
> s = BetterString.new("please matz")
> puts s[0]
> puts s[0..5]
> s[7] = "matz the great"
> puts s
> 
> joe@merry:~$ ./b.rb
> p
> please
> please matz the great
> 
> thanks,
> -joe