Skip to content

Commit 0a1deae

Browse files
committed
2-0-stable: Revert [8866]
git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/2-0-stable@8947 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
1 parent 833d3e4 commit 0a1deae

File tree

4 files changed

+18
-30
lines changed

4 files changed

+18
-30
lines changed

activerecord/CHANGELOG

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
*SVN*
22

3-
* Improve associations performance by avoiding named block arguments. #11109 [adymo]
4-
53
* Ensure that modifying has_and_belongs_to_many actions clear the query cache. Closes #10840 [john.andrews]
64

75
* Fix issue where Table#references doesn't pass a :null option to a *_type attribute for polymorphic associations. Closes #10753 [railsjitsu]

activerecord/lib/active_record/associations/association_collection.rb

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ def delete_all
4343
end
4444

4545
# Calculate sum using SQL, not Enumerable
46-
def sum(*args)
47-
calculate(:sum, *args) { |*block_args| yield(*block_args) if block_given? }
46+
def sum(*args, &block)
47+
calculate(:sum, *args, &block)
4848
end
4949

5050
# Remove +records+ from this association. Does not destroy +records+.
@@ -121,9 +121,9 @@ def empty?
121121
size.zero?
122122
end
123123

124-
def any?
124+
def any?(&block)
125125
if block_given?
126-
method_missing(:any?) { |*block_args| yield(*block_args) if block_given? }
126+
method_missing(:any?, &block)
127127
else
128128
!empty?
129129
end
@@ -157,13 +157,11 @@ def replace(other_array)
157157

158158

159159
protected
160-
def method_missing(method, *args)
160+
def method_missing(method, *args, &block)
161161
if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method))
162-
super { |*block_args| yield(*block_args) if block_given? }
162+
super
163163
else
164-
@reflection.klass.send(:with_scope, construct_scope) {
165-
@reflection.klass.send(method, *args) { |*block_args| yield(*block_args) if block_given? }
166-
}
164+
@reflection.klass.send(:with_scope, construct_scope) { @reflection.klass.send(method, *args, &block) }
167165
end
168166
end
169167

@@ -189,15 +187,15 @@ def find_target
189187

190188
private
191189

192-
def create_record(attrs)
190+
def create_record(attrs, &block)
193191
ensure_owner_is_not_new
194192
record = @reflection.klass.send(:with_scope, :create => construct_scope[:create]) { @reflection.klass.new(attrs) }
195-
add_record_to_target_with_callbacks(record) { |*block_args| yield(*block_args) if block_given? }
193+
add_record_to_target_with_callbacks(record, &block)
196194
end
197195

198-
def build_record(attrs)
196+
def build_record(attrs, &block)
199197
record = @reflection.klass.new(attrs)
200-
add_record_to_target_with_callbacks(record) { |*block_args| yield(*block_args) if block_given? }
198+
add_record_to_target_with_callbacks(record, &block)
201199
end
202200

203201
def add_record_to_target_with_callbacks(record)

activerecord/lib/active_record/associations/association_proxy.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,6 @@ def inspect
7878
@target.inspect
7979
end
8080

81-
def to_xml(options={}, &block)
82-
if load_target
83-
@target.to_xml(options, &block)
84-
end
85-
end
86-
8781
protected
8882
def dependent?
8983
@reflection.options[:dependent]
@@ -126,9 +120,9 @@ def merge_options_from_reflection!(options)
126120
end
127121

128122
private
129-
def method_missing(method, *args)
123+
def method_missing(method, *args, &block)
130124
if load_target
131-
@target.send(method, *args) { |*block_args| yield(*block_args) if block_given? }
125+
@target.send(method, *args, &block)
132126
end
133127
end
134128

activerecord/lib/active_record/associations/has_many_through_association.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ def size
113113
end
114114

115115
# Calculate sum using SQL, not Enumerable
116-
def sum(*args)
117-
calculate(:sum, *args) { |*block_args| yield(*block_args) if block_given? }
116+
def sum(*args, &block)
117+
calculate(:sum, *args, &block)
118118
end
119119

120120
def count(*args)
@@ -128,13 +128,11 @@ def count(*args)
128128
end
129129

130130
protected
131-
def method_missing(method, *args)
131+
def method_missing(method, *args, &block)
132132
if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method))
133-
super { |*block_args| yield(*block_args) if block_given? }
133+
super
134134
else
135-
@reflection.klass.send(:with_scope, construct_scope) {
136-
@reflection.klass.send(method, *args) { |*block_args| yield(*block_args) if block_given? }
137-
}
135+
@reflection.klass.send(:with_scope, construct_scope) { @reflection.klass.send(method, *args, &block) }
138136
end
139137
end
140138

0 commit comments

Comments
 (0)