Skip to content

Instantly share code, notes, and snippets.

@jpfuentes2
Created August 10, 2011 15:17
Show Gist options
  • Save jpfuentes2/1137095 to your computer and use it in GitHub Desktop.
Save jpfuentes2/1137095 to your computer and use it in GitHub Desktop.
scope golf
def self.define_scopes(&block)
class_eval do
missing = method(:method_missing)
undef :method_missing
def self.method_missing(method, *args, &block)
scope method, block
end
block.call
singleton_class.send(:redefine_method, :method_missing, &missing)
end
end
define_scopes do
by_building { |b| where(building: b) }
by_something_else { limit(5) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment