From: Matthew B Gardner Date: 2007-08-18T15:34:40+09:00 Subject: Re: Problem with Array#delete Sorry, I only meant the code I posted as an example of what is happening -- the actual code would be a little hard to gather and format, but I will do so if the following isn't enough information: ruby -v #=> ruby 1.8.4 (2005-12-24) [i486-linux] Ok, I threw this code in to gather some info, and following it is the printout: p world.characters.class p world.characters.size world.characters.each do |ch| p ch.class p ch.object_id end world.characters.delete(self) p world.characters Array 2 Character -607336504 Character -607410834 [] Do I need to format up the code, or is there something telling from the information here? Thanks, Matt On Saturday 18 August 2007 02:17, Morton Goldberg wrote: > On Aug 18, 2007, at 12:59 AM, 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. > > I ran your code and I didn't have a problem: it did what you > expected. Are you sure that the code you posted is exactly the same > as the code that is giving you trouble? > > Regards, Morton