Skip to content
This repository
Browse code

Merge pull request #12842 from kuldeepaggarwal/array_split

Speed up Array#split when block is passed
  • Loading branch information...
commit 15ef6bed18ce144d7fa0670b22d80aeeb4237bd8 2 parents d17e79b + 4aadd16
Guillermo Iguaran authored November 11, 2013
6  activesupport/lib/active_support/core_ext/array/grouping.rb
@@ -83,10 +83,10 @@ def in_groups(number, fill_with = nil)
83 83
   #
84 84
   #   [1, 2, 3, 4, 5].split(3)              # => [[1, 2], [4, 5]]
85 85
   #   (1..10).to_a.split { |i| i % 3 == 0 } # => [[1, 2], [4, 5], [7, 8], [10]]
86  
-  def split(value = nil, &block)
87  
-    if block
  86
+  def split(value = nil)
  87
+    if block_given?
88 88
       inject([[]]) do |results, element|
89  
-        if block.call(element)
  89
+        if yield(element)
90 90
           results << []
91 91
         else
92 92
           results.last << element

0 notes on commit 15ef6be

Please sign in to comment.
Something went wrong with that request. Please try again.