lib/hightop/enumerable.rb in hightop-0.2.1 vs lib/hightop/enumerable.rb in hightop-0.2.2
- old
+ new
@@ -1,8 +1,8 @@
module Enumerable
def top(*args, &block)
- if block || !respond_to?(:scoping)
+ if block || !(respond_to?(:scoping) || respond_to?(:with_scope))
limit, options, _ = args
if limit.is_a?(Hash) && args.size == 1
options = limit
limit = nil
end
@@ -17,10 +17,12 @@
counts.select! { |_, v| v >= min } if min
arr = counts.sort_by { |_, v| -v }
arr = arr[0...limit] if limit
Hash[arr]
- else
+ elsif respond_to?(:scoping)
scoping { @klass.send(:top, *args, &block) }
+ else
+ with_scope(self) { klass.send(:top, *args, &block) }
end
end
end