Skip to content

Instantly share code, notes, and snippets.

@jblanche
Created October 24, 2008 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jblanche/19419 to your computer and use it in GitHub Desktop.
Save jblanche/19419 to your computer and use it in GitHub Desktop.
module ScopedObject
def named_scope_first(name, options = {}, &block)
name = name.to_sym
scopes[name] = lambda do |parent_scope, *args|
Scope.new(parent_scope, case options
when Hash
options
when Proc
options.call(*args)
end, &block).first
end
(class << self; self end).instance_eval do
define_method name do |*args|
scopes[name].call(self, *args)
end
end
end
def self.included(mod)
puts "#{self} included in #{mod}"
end
class Scope < ActiveRecord::NamedScope::Scope
end
end
ActiveRecord::NamedScope::ClassMethods.send :include, ScopedObject
ActiveRecord::Base.send :include, ActiveRecord::NamedScope
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment