Skip to content

Commit f9cb645

Browse files
Yield only one argument instead of splatting.
Add Changelog entry. Closes rails#4003
1 parent 9cc2bf6 commit f9cb645

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

activerecord/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
## Rails 4.0.0 (unreleased) ##
22

3+
* Allow blocks for `count` with `ActiveRecord::Relation`, to work similar as
4+
`Array#count`:
5+
6+
Person.where("age > 26").count { |person| gender == 'female' }
7+
8+
*Chris Finne & Carlos Antonio da Silva*
9+
310
* Added support to `CollectionAssociation#delete` for passing `fixnum`
411
or `string` values as record ids. This finds the records responding
512
to the `id` and executes delete on them.

activerecord/lib/active_record/relation/calculations.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module Calculations
2121
# # => queries people where "age > 26" then count the loaded results filtering by gender
2222
def count(column_name = nil, options = {})
2323
if block_given?
24-
self.to_a.count { |*block_args| yield(*block_args) }
24+
self.to_a.count { |item| yield item }
2525
else
2626
column_name, options = nil, column_name if column_name.is_a?(Hash)
2727
calculate(:count, column_name, options)
@@ -65,7 +65,7 @@ def maximum(column_name, options = {})
6565
# # queries people where "age > 100" then perform a sum calculation with the block returns
6666
def sum(*args)
6767
if block_given?
68-
self.to_a.sum(*args) { |*block_args| yield(*block_args) }
68+
self.to_a.sum(*args) { |item| yield item }
6969
else
7070
calculate(:sum, *args)
7171
end

0 commit comments

Comments
 (0)