123456789_123456789_123456789_123456789_123456789_

Module: Mongoid::Extensions::Hash::ClassMethods

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#resizable?true (readonly)

Can the size of this object change?

Examples:

Is the hash resizable?

{}.resizable?

Returns:

  • (true)

    true.

[ GitHub ]

  
# File 'lib/mongoid/extensions/hash.rb', line 139

def resizable?
  true
end

Instance Method Details

#mongoize(object) ⇒ Hash | nil

Turn the object from the ruby type we deal with to a Mongo friendly type.

Examples:

Mongoize the object.

Hash.mongoize([ 1, 2, 3 ])

Parameters:

  • object (Object)

    The object to mongoize.

Returns:

  • (Hash | nil)

    The object mongoized or nil.

[ GitHub ]

  
# File 'lib/mongoid/extensions/hash.rb', line 123

def mongoize(object)
  return if object.nil?
  case object
  when BSON::Document
    object.dup.transform_values!(&:mongoize)
  when Hash
    BSON::Document.new(object.transform_values(&:mongoize))
  end
end