Skip to content

Instantly share code, notes, and snippets.

@fuCtor
Last active February 8, 2016 10:51
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 fuCtor/881f9d4945daa8fa3ac9 to your computer and use it in GitHub Desktop.
Save fuCtor/881f9d4945daa8fa3ac9 to your computer and use it in GitHub Desktop.
def counter(name)
name = name.to_s
@counters ||= {}
return unless name.present?
return @counters[name] if counters.key?(name)
return unless block_given?
relaion = yield
@counters[name.to_s] ||= relation.count if relation.respond_to? :count
end
# использование
= counter('product') { Product }
= counter('uniq_product') { Product.uniq }
= counter('product') - counter('uniq_product')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment