Method: BSON::Document#initialize

Defined in:
lib/bson/document.rb

#initialize(elements = nil) ⇒ Document

Instantiate a new Document. Valid parameters for instantiation is a hash only or nothing.

Examples:

Create the new Document.

BSON::Document.new(name: "Joe", age: 33)

Parameters:

  • elements (Hash) (defaults to: nil)

    The elements of the document.

Since:

  • 3.0.0



213
214
215
216
# File 'lib/bson/document.rb', line 213

def initialize(elements = nil)
  super()
  (elements || {}).each_pair{ |key, value| self[key] = value }
end