# Problem with array ... object inside disappear

**URL:** <https://www.ruby-forum.com/t/problem-with-array-object-inside-disappear/155220>\
**Category:** Ruby\
**Created:** [December 9, 2008, 2:59pm UTC](https://www.ruby-forum.com/t/problem-with-array-object-inside-disappear/155220 "2008-12-09T14:59:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrdamien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mrdamien](https://www.ruby-forum.com/u/mrdamien)\
**Post date:** [December 9, 2008, 2:59pm UTC](https://www.ruby-forum.com/t/problem-with-array-object-inside-disappear/155220/1 "2008-12-09T14:59:58Z")

</div>

Hi dudes,

I am becoming crazy with an array behaviour.

Here is the stuff.

I have an objet PackageList that keep an internal list of packages  
inside an array.

class PackageList  
def initialize  
@list = Array.new  
end

def refresh  
p @list # show list first time  
@list.each do |item|  
p item.name # show list second time  
end  
end

end

The problem here is that when I show the list for the first time I  
didn’t get the same result than the second time depiste I didn’t change  
anything in my list.

extract from first time  
[#\<Package:0x435e504 @maj\_number=3, @min\_number=2, @name=“test1”\>,  
#\<Package:0x435d604 @maj\_number=3, @min\_number=1, @name=“test2”\>,  
#\<Package:0x435cb64 @maj\_number=1, @min\_number=2, @name=“test3”\>, …]

extract from second time  
“test1”  
“test3”  
…

The “test2” object disappeared depiste I didn’t change anything. Now if  
I call the method for ‘each’ latter in the software, the “test2” object  
appears again.

I can’t find why the list is changing even if I didn’t touch anything.

---

<div class="post-metadata">

**Author:** ![mrdamien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mrdamien](https://www.ruby-forum.com/u/mrdamien)\
**Post date:** [December 9, 2008, 3:42pm UTC](https://www.ruby-forum.com/t/problem-with-array-object-inside-disappear/155220/2 "2008-12-09T15:42:42Z")

</div>

MR Damien wrote:

> OK, the problem seems to be with rake tasks. Inside one of them, there  
> is some delay between what it prints and the changes made to the list.
> 
> Weird.

Finally, I got it. I was modifying the array where I was iterating from  
that was causing weird issues.

I use 2 array now, problem solved.

---

<div class="post-metadata">

**Author:** ![mrdamien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mrdamien](https://www.ruby-forum.com/u/mrdamien)\
**Post date:** [December 9, 2008, 4:24pm UTC](https://www.ruby-forum.com/t/problem-with-array-object-inside-disappear/155220/3 "2008-12-09T16:24:48Z")

</div>

MR Damien wrote:

> MR Damien wrote:
> 
> > OK, the problem seems to be with rake tasks. Inside one of them, there  
> > is some delay between what it prints and the changes made to the list.
> > 
> > Weird.
> 
> Finally, I got it. I was modifying the array where I was iterating from  
> that was causing weird issues.
> 
> I use 2 array now, problem solved.

And Yes, I like to speak alone !!! 🙂

---

<div class="post-metadata">

**Author:** ![mrdamien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mrdamien](https://www.ruby-forum.com/u/mrdamien)\
**Post date:** [December 9, 2008, 3:25pm UTC](https://www.ruby-forum.com/t/problem-with-array-object-inside-disappear/155220/4 "2008-12-09T15:25:25Z")

</div>

OK, the problem seems to be with rake tasks. Inside one of them, there  
is some delay between what it prints and the changes made to the list.

Weird.
