w wg
9/27/2008 9:08:00 AM
Hi,
Please look:
> x = 2840
=> 2840
> x.object_id
=> 5681
> a = [1,2,3,4,5]
=> [1, 2, 3, 4, 5]
> a[4].object_id
=> 11
> a.each {|x| puts x}
1
2
3
4
5
=> [1, 2, 3, 4, 5]
>a[4].object_id
=> 11
> x.object_id
=> 11
After execute the block , it looks like that ruby destroied the former
'x' object, the 'x' object has object_id 4 now, which is same as
a[4].object_id.
If so , does it mean that I must choose another variable name in
array's each block to keep the 'x' object alive ?
Thank you.
--
Wwg