From: Dan Zwell Date: 2007-08-18T15:19:01+09:00 Subject: Re: Problem with Array#delete Matthew B Gardner wrote: > Hello, I'm baffled by the following problem: > > I have an Account class and an external array that keeps them in a list. I'm > trying to delete the account objects one at a time as needed, by: > > class Account > def quit > array_name.delete self > end > end > > However, this is deleting every account in the list (array_name == []). I've > verified that the account objects are unique. Just for an example, this is > the equivalent of what's happening: > > class Account > def quit arr > arr.delete self > end > end > > a1 = Account.new > a2 = Account.new > arr = [] > arr << a1 > arr << a2 > a1.quit arr > arr #=> [] > > > Has anyone else experienced this problem, or know what the likely cause is? I > have other arrays that work in the exact same fashion and work as expected. > > Thank you for any help, > Matt > > Wow, that was a well-asked question. This seems like a Ruby bug, though I can't reproduce it. When I run the code you posted, arr[] still contains a2 (as it should). I am using Ruby 1.8.6 (on Linux). What are you using? Dan