public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Performance: grouping helpers should use yield instead of block as argument.  
[#723 state:resolved]
miloops (author)
Tue Jul 29 19:14:56 -0700 2008
jeremy (committer)
Wed Jul 30 01:52:16 -0700 2008
commit  2617d0dc5ced4b354bff9633bddafdf80ad5a711
tree    55d3b7e076ab8541c4a890aeb6226ded657d35bc
parent  c4038764d2b4c05178cceb22066e0ece59fe49d2
...
19
20
21
22
 
23
24
25
...
31
32
33
34
 
35
36
37
...
87
88
89
90
91
 
 
92
93
94
 
95
96
97
...
19
20
21
 
22
23
24
25
...
31
32
33
 
34
35
36
37
...
87
88
89
 
 
90
91
92
93
 
94
95
96
97
0
@@ -19,7 +19,7 @@ module ActiveSupport #:nodoc:
0
         #   %w(1 2 3).in_groups_of(2, false) {|g| p g}
0
         #   ["1", "2"]
0
         #   ["3"]
0
-        def in_groups_of(number, fill_with = nil, &block)
0
+        def in_groups_of(number, fill_with = nil)
0
           if fill_with == false
0
             collection = self
0
           else
0
@@ -31,7 +31,7 @@ module ActiveSupport #:nodoc:
0
           end
0
 
0
           if block_given?
0
-            collection.each_slice(number, &block)
0
+            collection.each_slice(number) { |slice| yield(slice) }
0
           else
0
             returning [] do |groups|
0
               collection.each_slice(number) { |group| groups << group }
0
@@ -87,11 +87,11 @@ module ActiveSupport #:nodoc:
0
         #
0
         #   [1, 2, 3, 4, 5].split(3)                # => [[1, 2], [4, 5]]
0
         #   (1..10).to_a.split { |i| i % 3 == 0 }   # => [[1, 2], [4, 5], [7, 8], [10]]
0
-        def split(value = nil, &block)
0
-          block ||= Proc.new { |e| e == value }
0
+        def split(value = nil)
0
+          using_block = block_given?
0
 
0
           inject([[]]) do |results, element|
0
-            if block.call(element)
0
+            if (using_block && yield(element)) || (value == element)
0
               results << []
0
             else
0
               results.last << element

Comments