Method: Mongoid::Contextual::Memory#each

Defined in:
lib/mongoid/contextual/memory.rb

#eachEnumerator

Iterate over the context. If provided a block, yield to a Mongoid document for each, otherwise return an enum.

Examples:

Iterate over the context.

context.each do |doc|
  puts doc.name
end

Returns:

  • (Enumerator)

    The enumerator.



99
100
101
102
103
104
105
106
107
108
# File 'lib/mongoid/contextual/memory.rb', line 99

def each
  if block_given?
    documents_for_iteration.each do |doc|
      yield(doc)
    end
    self
  else
    to_enum
  end
end