From d6cfbaea72e1b2852ed3206c0ffea8a572048369 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Tue, 18 Jun 2013 03:32:01 -0700 Subject: Change Result#each to return an Enumerator when called without a block. As with #10992, this lets us call #with_index, etc on the results. --- activerecord/lib/active_record/result.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/result.rb b/activerecord/lib/active_record/result.rb index bea195e9b8..6156b3a5ba 100644 --- a/activerecord/lib/active_record/result.rb +++ b/activerecord/lib/active_record/result.rb @@ -18,7 +18,11 @@ module ActiveRecord end def each - hash_rows.each { |row| yield row } + if block_given? + hash_rows.each { |row| yield row } + else + hash_rows.to_enum + end end def to_hash -- cgit v1.2.3