diff options
Diffstat (limited to 'activerecord/lib/active_record/associations/association_collection.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/association_collection.rb | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index 79cd227c0c..d400a5c772 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -43,8 +43,8 @@ module ActiveRecord end # Calculate sum using SQL, not Enumerable - def sum(*args, &block) - calculate(:sum, *args, &block) + def sum(*args) + calculate(:sum, *args) { |*block_args| yield(*block_args) if block_given? } end # Remove +records+ from this association. Does not destroy +records+. @@ -121,9 +121,9 @@ module ActiveRecord size.zero? end - def any?(&block) + def any? if block_given? - method_missing(:any?, &block) + method_missing(:any?) { |*block_args| yield(*block_args) if block_given? } else !empty? end @@ -157,11 +157,13 @@ module ActiveRecord protected - def method_missing(method, *args, &block) + def method_missing(method, *args) if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method)) - super + super { |*block_args| yield(*block_args) if block_given? } else - @reflection.klass.send(:with_scope, construct_scope) { @reflection.klass.send(method, *args, &block) } + @reflection.klass.send(:with_scope, construct_scope) { + @reflection.klass.send(method, *args) { |*block_args| yield(*block_args) if block_given? } + } end end @@ -187,15 +189,15 @@ module ActiveRecord private - def create_record(attrs, &block) + def create_record(attrs) ensure_owner_is_not_new record = @reflection.klass.send(:with_scope, :create => construct_scope[:create]) { @reflection.klass.new(attrs) } - add_record_to_target_with_callbacks(record, &block) + add_record_to_target_with_callbacks(record) { |*block_args| yield(*block_args) if block_given? } end - def build_record(attrs, &block) + def build_record(attrs) record = @reflection.klass.new(attrs) - add_record_to_target_with_callbacks(record, &block) + add_record_to_target_with_callbacks(record) { |*block_args| yield(*block_args) if block_given? } end def add_record_to_target_with_callbacks(record) |