Method: Mongoid::Scope#initialize

Defined in:
lib/mongoid/scope.rb

#initialize(parent, conditions, &block) ⇒ Scope

Create the new Scope. If a block is passed in, this Scope will extend the block.

Options:

parent: The class the scope belongs to, or a parent Scope. conditions: A Hash of conditions.

Example:

Mongoid::Scope.new(Person, { :title => "Sir" }) do
  def knighted?
    title == "Sir"
  end
end


38
39
40
41
# File 'lib/mongoid/scope.rb', line 38

def initialize(parent, conditions, &block)
  @parent, @conditions = parent, conditions
  extend Module.new(&block) if block_given?
end