Todd Benson wrote:
> On Sun, Apr 26, 2009 at 11:03 PM, Todd Benson <caduceass / gmail.com> 
> wrote:
>> to me if it did.
> Let me rephrase.  What is different on the underlying structure with
> [1..-1] and #shift?  I'm not sure if shift really moves everything,
> but if it does, I wouldn't mind knowing.
> 
> Todd

shift changes the array in place:

1)
arr = [10, 20, 30]

y = arr.shift
puts y
p arr

--output:--
10
[20, 30]


subscripts create a new array:

2)
arr = [10, 20, 30]
p arr
print "id: ", arr.object_id
puts

x = arr[1..-1]
p x
print "id: ", x.object_id
puts
p arr

--output:--
[10, 20, 30]
id: 75950
[20, 30]
id: 75860
[10, 20, 30]

> Is that really what happens?  I thought it just reassigned a starting
> point, and indexed from there.  At least, that would make more sense
> to me if it did.

Would it?  What if you had an array that took up 3GB of memory and you 
shifted off every element but the last one.  Would you expect your array 
to still occupy 3GB of memory?
-- 
Posted via http://www.ruby-forum.com/.