# Deleting an object from an array

**URL:** <https://www.ruby-forum.com/t/deleting-an-object-from-an-array/56740>\
**Category:** Ruby\
**Created:** [April 3, 2006, 2:47pm UTC](https://www.ruby-forum.com/t/deleting-an-object-from-an-array/56740 "2006-04-03T14:47:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![markcasio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9bcb4/32.png) [@markcasio](https://www.ruby-forum.com/u/markcasio)\
**Post date:** [April 3, 2006, 2:47pm UTC](https://www.ruby-forum.com/t/deleting-an-object-from-an-array/56740/1 "2006-04-03T14:47:27Z")

</div>

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) }

---

<div class="post-metadata">

**Author:** ![markcasio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9bcb4/32.png) [@markcasio](https://www.ruby-forum.com/u/markcasio)\
**Post date:** [April 3, 2006, 5:09pm UTC](https://www.ruby-forum.com/t/deleting-an-object-from-an-array/56740/2 "2006-04-03T17:09:53Z")

</div>

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
