Skip to content

Instantly share code, notes, and snippets.

@pjb3
Created December 14, 2010 14:16
Show Gist options
  • Select an option

  • Save pjb3/740476 to your computer and use it in GitHub Desktop.

Select an option

Save pjb3/740476 to your computer and use it in GitHub Desktop.
Fixes ActiveRecord's named_scope API. Place this into config/initializers/def_scope.rb
# Having to use a lambda when defining a scope is ugly and stupid
# I've never had a use case for a scope extension
# This allows us to just use a block
module DefScope
def def_scope(name, &blk)
scope name, blk
end
end
ActiveRecord::Base.extend DefScope
# Usage example:
#
# class Person < ActiveRecord::Base
# def_scope :active_as_of do |date|
# { :conditions => ["active_at > ?", date] }
# end
# end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment