Created
October 22, 2011 22:54
-
-
Save jcalvert/1306596 to your computer and use it in GitHub Desktop.
Boolean class method companions for named_scopes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveRecord | |
module NamedScope | |
module ClassMethods | |
alias_method :original_scope, :scope | |
def scope(name, scope_options = {}) | |
original_scope(name, scope_options) | |
boolean_scope = lambda do | |
send(name).any? | |
end | |
singleton_class.send(:redefine_method, "#{name}?".to_sym, &boolean_scope) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment