Skip to content

Instantly share code, notes, and snippets.

@jkarmel
Created December 18, 2014 23:20
Show Gist options
  • Save jkarmel/fdba4380db69ac353d46 to your computer and use it in GitHub Desktop.
Save jkarmel/fdba4380db69ac353d46 to your computer and use it in GitHub Desktop.
module SendAll
def send_all(methods_and_args)
return self if methods_and_args.empty?
method_name, args = methods_and_args.pop
result = send method_name, *args
result.send_all result, query
end
end
class ActiveRecord::Relation
self.instance_eval { include SendAll }
end
Developer.send_all [
[:with_interest_bucket_ids_including, [1,2,3]],
[:with_location_bucket_ids_includint, [3,4,5]]
]
# This could then be used in controllers to chain scopes depending on a query
Developer.send_all developer_params.to_a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment