Method: Mongoid::Extensions::Array#delete_one

Defined in:
lib/mongoid/extensions/array.rb

#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 since it does not perform multiple deletes.

Examples:

Delete the first object.

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

Parameters:

  • object (Object)

    The object to delete.

Returns:

  • (Object)

    The deleted object.



91
92
93
94
# File 'lib/mongoid/extensions/array.rb', line 91

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