Methods
Classes and Modules
Module ActiveRecord::NamedScope::ClassMethods
Class ActiveRecord::NamedScope::Scope
Public Class methods
included(base)

All subclasses of ActiveRecord::Base have two named_scopes:

  • all, which is similar to a find(:all) query, and
  • scoped, which allows for the creation of anonymous scopes, on the fly: Shirt.scoped(:conditions => {:color => ‘red’}).scoped(:include => :washing_instructions)

These anonymous scopes tend to be useful when procedurally generating complex queries, where passing intermediate values (scopes) around as first-class objects is convenient.

    # File lib/active_record/named_scope.rb, line 9
 9:     def self.included(base)
10:       base.class_eval do
11:         extend ClassMethods
12:         named_scope :scoped, lambda { |scope| scope }
13:       end
14:     end