Aleksi Niemel<aleksi.niemela / cinnober.com> writes:

> I hope I don't let you down by writing a couple.

Nope - they were a good couple.

> As an idiom Array#[pos,len]= works ok, but have couple of traps. First, it
> autoflattens. Second it doesn't work intuitively with negative
> indices.

True 'nuff, although

   b = [1,2,3]
   a[1,0] = [b]

Does what you'd want.

Not being able to extend at the end is a problem, but then there's
always #push

> it enhances code readibility:
> 
>   ary, other = [1,2,3], [4,5]
>   ary[1,0] = other      # vs.
>   ary.insert(1, other)

I personally find the [] form pretty readable, but I'm funny that
way. I tend to view the function-style more Perl-like.

A good side-effect of the functional form is that it can return the
array (whereas the assignment returns the rvalue) so you can chain
calls

  a.insert(5, x).insert(2, y)

However, can I make a suggestion?

Let's not implement this in C code, but in a Ruby-language module. Let 
people use it that way and get experience with it before making code
changes in the interpreter.

Regards


Dave