W
w wg
Hi,
Please look:
2
3
4
5
=> [1, 2, 3, 4, 5]
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.
Please look:
=> 5681x = 2840 => 2840
x.object_id
=> 11a = [1,2,3,4,5] => [1, 2, 3, 4, 5]
a[4].object_id
1a.each {|x| puts x}
2
3
4
5
=> [1, 2, 3, 4, 5]
=> 11a[4].object_id
=> 11x.object_id
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.