I have a class variable that collects all the instance variables. It also had a method for getting them and deleting them.
module Somemodule
class Widget
@@widgets = []
def initialize
...
@@widgets << self
end
def self.all
@@widgets
end
def delete
@@widgets.delete(self)
end
end
end
In my code, I want to delete widgets sometimes.
module Somemodule
def self.delete_bad_widgets
Widget.all.each do |widget|
if widget.bad
widget.delete
end
end
end
end
The problem is that this doesn't delete all the bad widgets. If I call Widget.all afterwards, I can still see bad widgets. Anyone have any idea what's going on? I'm running Ruby 2.2.1.
Thank you
EDIT: all in all there are about 4500 widgets and the code changes them a couple of times. But I can still run something like the following (in the same delete_bad_widgets method!) and still see bad widgets:
Widget.all.each {|w| pp w if w.bad}
eql?(I think that's what's used) is implemented correctly.widget.badconditional is working as you think it is.