Method: Mongoid::Extensions::Array::ClassMethods#mongoize

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

#mongoize(object) ⇒ Array | nil

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

Examples:

Mongoize the object.

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

Parameters:

  • object (Object)

    The object to mongoize.

Returns:

  • (Array | nil)

    The object mongoized or nil.



136
137
138
139
140
141
142
# File 'lib/mongoid/extensions/array.rb', line 136

def mongoize(object)
  return if object.nil?
  case object
  when ::Array, ::Set
    object.map(&:mongoize)
  end
end