diff options
Diffstat (limited to 'activerecord/lib/active_record/scoping/named.rb')
-rw-r--r-- | activerecord/lib/active_record/scoping/named.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/scoping/named.rb b/activerecord/lib/active_record/scoping/named.rb index 49cadb66d0..826b710e92 100644 --- a/activerecord/lib/active_record/scoping/named.rb +++ b/activerecord/lib/active_record/scoping/named.rb @@ -148,9 +148,13 @@ module ActiveRecord extension = Module.new(&block) if block singleton_class.send(:define_method, name) do |*args| - scope = all.scoping { body.call(*args) } + if body.respond_to?(:to_proc) + scope = all.scoping { instance_exec(*args, &body) } + else + # Body is given as an object instead of a block, so invoke call() + scope = all.scoping { body.call(*args) } + end scope = scope.extending(extension) if extension - scope || all end end |