Deleting an object from an array


#1

I assumed incorrectly that Array#delete deleted a specific object,
using eql? (identity). I later discovered that it uses == (same
values). Then I looked for a method to delete using eql? and couldn’t
find one. I ended up using the following. Is there a better way?

obj_to_delete = whatever
my_array.delete_if { |element| element.eql?(object_to_delete) }


#2

On Mon, 3 Apr 2006, Mark V. wrote:

I assumed incorrectly that Array#delete deleted a specific object,
using eql? (identity). I later discovered that it uses == (same
values). Then I looked for a method to delete using eql? and couldn’t
find one. I ended up using the following. Is there a better way?

obj_to_delete = whatever
my_array.delete_if { |element| element.eql?(object_to_delete) }

probably not, but if you’re doing alot of this kind of override you
might to

class IndentArray < ::Array
alias_method “==”, “eql?”
end

etc.

-a