diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 4a2ed49776f67..118e3b4d7781f 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,7 +1,5 @@ *SVN* -* Improve associations performance by avoiding named block arguments. #11109 [adymo] - * Ensure that modifying has_and_belongs_to_many actions clear the query cache. Closes #10840 [john.andrews] * Fix issue where Table#references doesn't pass a :null option to a *_type attribute for polymorphic associations. Closes #10753 [railsjitsu] diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index d400a5c772abe..79cd227c0c59d 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -43,8 +43,8 @@ def delete_all end # Calculate sum using SQL, not Enumerable - def sum(*args) - calculate(:sum, *args) { |*block_args| yield(*block_args) if block_given? } + def sum(*args, &block) + calculate(:sum, *args, &block) end # Remove +records+ from this association. Does not destroy +records+. @@ -121,9 +121,9 @@ def empty? size.zero? end - def any? + def any?(&block) if block_given? - method_missing(:any?) { |*block_args| yield(*block_args) if block_given? } + method_missing(:any?, &block) else !empty? end @@ -157,13 +157,11 @@ def replace(other_array) protected - def method_missing(method, *args) + def method_missing(method, *args, &block) if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method)) - super { |*block_args| yield(*block_args) if block_given? } + super else - @reflection.klass.send(:with_scope, construct_scope) { - @reflection.klass.send(method, *args) { |*block_args| yield(*block_args) if block_given? } - } + @reflection.klass.send(:with_scope, construct_scope) { @reflection.klass.send(method, *args, &block) } end end @@ -189,15 +187,15 @@ def find_target private - def create_record(attrs) + def create_record(attrs, &block) 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_args| yield(*block_args) if block_given? } + add_record_to_target_with_callbacks(record, &block) end - def build_record(attrs) + def build_record(attrs, &block) record = @reflection.klass.new(attrs) - add_record_to_target_with_callbacks(record) { |*block_args| yield(*block_args) if block_given? } + add_record_to_target_with_callbacks(record, &block) end def add_record_to_target_with_callbacks(record) diff --git a/activerecord/lib/active_record/associations/association_proxy.rb b/activerecord/lib/active_record/associations/association_proxy.rb index 16a2943c76df9..ed1dd36f75290 100644 --- a/activerecord/lib/active_record/associations/association_proxy.rb +++ b/activerecord/lib/active_record/associations/association_proxy.rb @@ -78,12 +78,6 @@ def inspect @target.inspect end - def to_xml(options={}, &block) - if load_target - @target.to_xml(options, &block) - end - end - protected def dependent? @reflection.options[:dependent] @@ -126,9 +120,9 @@ def merge_options_from_reflection!(options) end private - def method_missing(method, *args) + def method_missing(method, *args, &block) if load_target - @target.send(method, *args) { |*block_args| yield(*block_args) if block_given? } + @target.send(method, *args, &block) end end diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb index 85bc86443f36d..883375707d9e3 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -113,8 +113,8 @@ def size end # Calculate sum using SQL, not Enumerable - def sum(*args) - calculate(:sum, *args) { |*block_args| yield(*block_args) if block_given? } + def sum(*args, &block) + calculate(:sum, *args, &block) end def count(*args) @@ -128,13 +128,11 @@ def count(*args) end protected - def method_missing(method, *args) + def method_missing(method, *args, &block) if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method)) - super { |*block_args| yield(*block_args) if block_given? } + super else - @reflection.klass.send(:with_scope, construct_scope) { - @reflection.klass.send(method, *args) { |*block_args| yield(*block_args) if block_given? } - } + @reflection.klass.send(:with_scope, construct_scope) { @reflection.klass.send(method, *args, &block) } end end