[LRUG] Array.slice question
Michael Pavling
pavling at gmail.com
Wed Sep 7 03:22:45 PDT 2011
On 7 September 2011 10:17, William Hamilton <whamilton42 at hotmail.com> wrote:
> The key point is that the 3 in a[3] and the 3 in a[3,0] are not referring to
> the same thing.
> a[3] is directly accessing an element within the array. a[3,0] is accessing
> a portion of the array. This diagram should help (if the formatting makes it
> through.. copy and paste to fixed-width if it doesn't):
Came through fine here - thanks, a picture speaks a thousand words :-)
> I think the *reason* Ruby behaves like this for arrays is because it's
> beneficial for Strings. If you wanted to
> insert a character at the end of a string, you could do s[3,0] = 'd'.
Excellent. That makes sense, and makes sense of the documentation.
I've had a fiddle with that in the console, and it works as you
suggest, so lots less confusion here :-)
Thank you!
More information about the Chat
mailing list