Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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