Index: lib/active_record/associations/association_proxy.rb =================================================================== --- lib/active_record/associations/association_proxy.rb (revision 2486) +++ lib/active_record/associations/association_proxy.rb (revision 5525) @@ -118,9 +118,13 @@ end private - def method_missing(method, *args, &block) + def method_missing(method, *args) if load_target - @target.send(method, *args, &block) + if block_given? + @target.send(method, *args) { |*block_args| yield(*block_args) } + else + @target.send(method, *args) + end end end Index: lib/active_record/associations/association_collection.rb =================================================================== --- lib/active_record/associations/association_collection.rb (revision 2486) +++ lib/active_record/associations/association_collection.rb (revision 5525) @@ -43,8 +43,12 @@ end # Calculate sum using SQL, not Enumerable - def sum(*args, &block) - calculate(:sum, *args, &block) + def sum(*args) + if block_given? + calculate(:sum, *args) { |*block_args| yield(*block_args) } + else + calculate(:sum, *args) + end end # Remove +records+ from this association. Does not destroy +records+. Index: lib/active_record/associations/has_and_belongs_to_many_association.rb =================================================================== --- lib/active_record/associations/has_and_belongs_to_many_association.rb (revision 2486) +++ lib/active_record/associations/has_and_belongs_to_many_association.rb (revision 5525) @@ -86,12 +86,20 @@ alias :concat_with_attributes :push_with_attributes 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 + if block_given? + super { |*block_args| yield(*block_args) } + else + super + end else @reflection.klass.with_scope(:find => { :conditions => @finder_sql, :joins => @join_sql, :readonly => false }) do - @reflection.klass.send(method, *args, &block) + if block_given? + @reflection.klass.send(method, *args) { |*block_args| yield(*block_args) } + else + @reflection.klass.send(method, *args) + end end end end Index: lib/active_record/associations/has_many_association.rb =================================================================== --- lib/active_record/associations/has_many_association.rb (revision 2486) +++ lib/active_record/associations/has_many_association.rb (revision 5525) @@ -93,9 +93,13 @@ end 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 + if block_given? + super { |*block_args| yield(*block_args) } + else + super + end else create_scoping = {} set_belongs_to_association_for(create_scoping) @@ -108,7 +112,11 @@ :readonly => false } ) do - @reflection.klass.send(method, *args, &block) + if block_given? + @reflection.klass.send(method, *args) { |*block_args| yield(*block_args) } + else + @reflection.klass.send(method, *args) + end end end end Index: lib/active_record/associations/has_many_through_association.rb =================================================================== --- lib/active_record/associations/has_many_through_association.rb (revision 2486) +++ lib/active_record/associations/has_many_through_association.rb (revision 5525) @@ -98,16 +98,30 @@ end # Calculate sum using SQL, not Enumerable - def sum(*args, &block) - calculate(:sum, *args, &block) + def sum(*args) + if block_given? + calculate(:sum, *args) { |*block_args| yield(*block_args) } + else + calculate(:sum, *args) + end end 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 + if block_given? + super { |*block_args| yield(*block_args) } + else + super + end else - @reflection.klass.with_scope(construct_scope) { @reflection.klass.send(method, *args, &block) } + @reflection.klass.with_scope(construct_scope) { + if block_given? + @reflection.klass.send(method, *args) { |*block_args| yield(*block_args) } + else + @reflection.klass.send(method, *args) + end + } end end