Module: Mongoid::Extensions::Array::Deletion

Included in:
Array
Defined in:
lib/mongoid/extensions/array/deletion.rb

Overview

This module contains deletion helpers for arrays.

Instance Method Summary collapse

Instance Method Details

#delete_one(object) ⇒ Object

Delete the first object in the array that is equal to the supplied object and return it. This is much faster than performing a standard delete for large arrays ince it attempt to delete multiple in the other.

Examples:

Delete the first object.

[ "1", "2", "1" ].delete_one("1")

Parameters:

  • object (Object)

    The object to delete.

Returns:

  • (Object)

    The deleted object.

Since:

  • 2.1.0



22
23
24
25
# File 'lib/mongoid/extensions/array/deletion.rb', line 22

def delete_one(object)
  position = index(object)
  position ? delete_at(position) : nil
end