aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorGuillermo Iguaran <guilleiguaran@gmail.com>2013-11-11 00:02:50 -0800
committerGuillermo Iguaran <guilleiguaran@gmail.com>2013-11-11 00:02:50 -0800
commit15ef6bed18ce144d7fa0670b22d80aeeb4237bd8 (patch)
tree608e21ad7bb17144e72ae6c7f631dfe8ed618372 /activesupport
parentd17e79b0f39f6300f10f6bda752ed36ea44137f2 (diff)
parent4aadd160ff96839e2e87399ab90f85437b1218a8 (diff)
downloadrails-15ef6bed18ce144d7fa0670b22d80aeeb4237bd8.tar.gz
rails-15ef6bed18ce144d7fa0670b22d80aeeb4237bd8.tar.bz2
rails-15ef6bed18ce144d7fa0670b22d80aeeb4237bd8.zip
Merge pull request #12842 from kuldeepaggarwal/array_split
Speed up Array#split when block is passed
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/array/grouping.rb6
1 files changed, 3 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/core_ext/array/grouping.rb b/activesupport/lib/active_support/core_ext/array/grouping.rb
index 59bf704d65..3529d57174 100644
--- a/activesupport/lib/active_support/core_ext/array/grouping.rb
+++ b/activesupport/lib/active_support/core_ext/array/grouping.rb
@@ -83,10 +83,10 @@ class Array
#
# [1, 2, 3, 4, 5].split(3) # => [[1, 2], [4, 5]]
# (1..10).to_a.split { |i| i % 3 == 0 } # => [[1, 2], [4, 5], [7, 8], [10]]
- def split(value = nil, &block)
- if block
+ def split(value = nil)
+ if block_given?
inject([[]]) do |results, element|
- if block.call(element)
+ if yield(element)
results << []
else
results.last << element