123456789_123456789_123456789_123456789_123456789_

Module: Mongoid::Extensions::BsonDocument

Relationships & Source Files
Defined in: lib/mongoid/extensions/bson_document.rb

Overview

Adds behavior to BSON::Document.

Instance Method Summary

Instance Method Details

#__deep_copy__BSON::Document

Make a deep copy of this document, preserving the BSON::Document type.

Hash#deep_copy returns a plain Hash, which causes field_was to return a different type than the field getter when the stored attribute is a BSON::Document.

Examples:

Make a deep copy of the document.

doc.__deep_copy__

Returns:

  • (BSON::Document)

    The copied document.

[ GitHub ]

  
# File 'lib/mongoid/extensions/bson_document.rb', line 17

def __deep_copy__
  self.class.new.tap do |copy|
    each_pair do |key, value|
      copy.store(key, value.__deep_copy__)
    end
  end
end